summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoop Talasila <talasila@research.att.com>2020-01-31 15:26:05 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-31 15:26:05 +0000
commitc345a2309421097ba02de062fcbfccd0c0f3be9d (patch)
tree955c98361b06e94300b067c9ed801f28e82b8a2e
parent2edccd7e8ef958d4891ba6de87a449daeb7593fe (diff)
parenta231d482351c64dc35563821d9531981ba28d4f3 (diff)
Merge "Fix NullPointerException & other sonar issues"
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java101
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java26
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImpl.java4
3 files changed, 66 insertions, 65 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java
index 517d2672..75f18c06 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java
@@ -132,6 +132,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorControllerAsync.class);
private static final String INVALID_ACTION = "[Controller.processRequest]Invalid raptor action [";
private static final String UNABLE_INSTANTIATE = "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: ";
+ private static final String FALSE = "false";
private String viewName;
@@ -197,8 +198,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
String sqlWhole = rr.getReportDataSQL(userId, downloadLimit, request);
request.setAttribute(AppConstants.RI_REPORT_SQL_WHOLE, sqlWhole);
}
- try {
- OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
+ try(OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream())) {
if ("report.download.pdf.session".equals(actionKey)) {
new PdfReportHandler().createPdfFileContent(request, response, 3);
@@ -261,27 +261,27 @@ public class RaptorControllerAsync extends RestrictedBaseController {
} catch (ClassNotFoundException e) {
logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION
- + actionKey + "]. ClassNotFoundException: " + e.getMessage()));
+ + actionKey + "]. ClassNotFoundException: "), e);
viewName = (new ErrorHandler()).processFatalErrorJSON(request,
new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage()));
} catch (IllegalAccessException e) {
logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION
- + actionKey + "]. IllegalAccessException: " + e.getMessage()));
+ + actionKey + "]. IllegalAccessException: "), e);
viewName = (new ErrorHandler()).processFatalErrorJSON(request,
new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage()));
} catch (InstantiationException e) {
logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION
- + actionKey + "]. InstantiationException: " + e.getMessage()));
+ + actionKey + "]. InstantiationException: "), e);
viewName = (new ErrorHandler()).processFatalErrorJSON(request,
new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage()));
} catch (NoSuchMethodException e) {
logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION
- + actionKey + "]. NoSuchMethodException: " + e.getMessage()));
+ + actionKey + "]. NoSuchMethodException: "), e);
viewName = (new ErrorHandler()).processFatalErrorJSON(request,
new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage()));
} catch (InvocationTargetException e) {
logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION
- + actionKey + "]. InvocationTargetException: " + e.getMessage()));
+ + actionKey + "]. InvocationTargetException: "), e);
viewName = (new ErrorHandler()).processFatalErrorJSON(request,
new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage()));
} finally {
@@ -590,7 +590,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
fft.setPredefinedValueList(predefinedValueList);
List<IdNameBooleanJSON> predefList = formEditJSON.getPredefinedValueList();
- if (predefList != null && predefList.size() > 0) {
+ if (predefList != null && !predefList.isEmpty()) {
for (IdNameBooleanJSON item : predefList) {
fft.getPredefinedValueList().getPredefinedValue().add(item.getId());
}
@@ -631,7 +631,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
wizardJSON.setTabId("FormEdit");
wizardJSON.setTabName("Form Edit");
String fieldId ="";
- if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().size()==0)
+ if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().isEmpty())
fieldId = "ff1";
else
fieldId = "ff"+(rdef.getFormFieldList().getFormField().size()+1);
@@ -893,8 +893,9 @@ public class RaptorControllerAsync extends RestrictedBaseController {
}
if (id.equals("Create")) {
rdef.persistReport(request);
- } else
+ } else {
persistReportDefinition(request, rdef);
+ }
messageJSON.setMessage("Success Definition of given report is saved in session.");
messageJSON.setAnyStacktrace((newReport ? " New Report info is added to Session "
: rdef.getReportID() + "- is Modified and added to session and DB."));
@@ -1167,16 +1168,16 @@ public class RaptorControllerAsync extends RestrictedBaseController {
public @ResponseBody Map<String,String> addSelectedReportUser(
@RequestBody String userIdToAdd, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
- JsonResponse.put("status","success");
- JsonResponse.put("userId",userIdToAdd);
+ jsonResponse.put("status","success");
+ jsonResponse.put("userId",userIdToAdd);
String action = "Add User";
rdef.getReportSecurity().addUserAccess(userIdToAdd, "Y");
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1188,17 +1189,17 @@ public class RaptorControllerAsync extends RestrictedBaseController {
public @ResponseBody Map<String,String> removeSelectedReportUser(
@RequestBody String userIdToRemove, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
- JsonResponse.put("status","success");
- JsonResponse.put("userId",userIdToRemove);
+ jsonResponse.put("status","success");
+ jsonResponse.put("userId",userIdToRemove);
String action = "Delete User";
rdef.getReportSecurity().removeUserAccess(userIdToRemove);
rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1209,16 +1210,16 @@ public class RaptorControllerAsync extends RestrictedBaseController {
@RequestMapping(value = "/report/security/addReportRole", method = RequestMethod.POST)
public @ResponseBody Map<String,String> addSelectedReportRole(
@RequestBody String roleIdToAdd, HttpServletRequest request, HttpServletResponse response) {
- Map<String, String> JsonResponse = new HashMap<>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
- JsonResponse.put("status","success");
- JsonResponse.put("roleId",roleIdToAdd);
+ jsonResponse.put("status","success");
+ jsonResponse.put("roleId",roleIdToAdd);
String action = "Add Role";
rdef.getReportSecurity().addRoleAccess(roleIdToAdd, "Y");
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1230,16 +1231,16 @@ public class RaptorControllerAsync extends RestrictedBaseController {
public @ResponseBody Map<String,String> removeSelectedReportRole(
@RequestBody String roleIdToRemove, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<String, String>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
- JsonResponse.put("status","success");
- JsonResponse.put("roleId",roleIdToRemove);
+ jsonResponse.put("status","success");
+ jsonResponse.put("roleId",roleIdToRemove);
String action = "Delete Role";
rdef.getReportSecurity().removeRoleAccess(roleIdToRemove);
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1252,17 +1253,17 @@ public class RaptorControllerAsync extends RestrictedBaseController {
@RequestBody Map<String,String> securityInfo, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
- JsonResponse.put("status","success");
- String OwnerUserId = securityInfo.get("userId");
+ jsonResponse.put("status","success");
+ String ownerUserId = securityInfo.get("userId");
String isPublic = securityInfo.get("isPublic");
boolean rPublic = isPublic.equals("true");
- rdef.getReportSecurity().setOwnerID(OwnerUserId);
+ rdef.getReportSecurity().setOwnerID(ownerUserId);
rdef.setPublic(rPublic);
persistReportDefinition(request, rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
@@ -1276,11 +1277,11 @@ public class RaptorControllerAsync extends RestrictedBaseController {
@PathVariable("userID") String userId,
@RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
String action ="";
- JsonResponse.put("status","success");
+ jsonResponse.put("status","success");
if (readOnly.equals("N")) {
action = "Grant User Access";
} else {
@@ -1290,7 +1291,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1303,11 +1304,11 @@ public class RaptorControllerAsync extends RestrictedBaseController {
@PathVariable("roleID") String roleId,
@RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response)
{
- Map<String, String> JsonResponse = new HashMap<String, String>();
+ Map<String, String> jsonResponse = new HashMap<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
try {
String action ="";
- JsonResponse.put("status","success");
+ jsonResponse.put("status","success");
if (readOnly.equals("N")) {
action = "Grant Role Access";
} else {
@@ -1317,7 +1318,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
WizardSequence ws = rdef.getWizardSequence();
ws.performAction(action,rdef);
- return JsonResponse;
+ return jsonResponse;
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,
"[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
@@ -1330,7 +1331,7 @@ public class RaptorControllerAsync extends RestrictedBaseController {
throws RaptorException {
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
- List<IdNameValue> UserList = new ArrayList<>();
+ List<IdNameValue> userList = new ArrayList<>();
List excludeValues = new java.util.ArrayList();
HttpSession session = request.getSession();
String query = Globals.getCustomizedScheduleQueryForUsers();
@@ -1358,9 +1359,9 @@ public class RaptorControllerAsync extends RestrictedBaseController {
} // if
if (!exclude)
- UserList.add(value);
+ userList.add(value);
} // for
- return UserList;
+ return userList;
}
@@ -1393,10 +1394,8 @@ public class RaptorControllerAsync extends RestrictedBaseController {
List<SecurityEntry> reportUserMapList = new ArrayList<>();
ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
Vector reportUsers = rdef.getReportUsers(request);
- int iCount = 0;
-
- for(Iterator iter=reportUsers.iterator(); iter.hasNext(); iCount++) {
- Map<String, String> reportUserMap = new HashMap<String,String>();
+
+ for(Iterator iter=reportUsers.iterator(); iter.hasNext();) {
SecurityEntry rUser = (SecurityEntry) iter.next();
reportUserMapList.add(rUser);
}
@@ -1560,13 +1559,13 @@ public class RaptorControllerAsync extends RestrictedBaseController {
wizardJSON.setDbInfoList(dbInfoList);
/*Robert add*/
- wizardJSON.setOneTimeRec((rdef != null) ? rdef.getIsOneTimeScheduleAllowed() : "false");
- wizardJSON.setHourlyRec((rdef != null) ? rdef.getIsHourlyScheduleAllowed() : "false");
- wizardJSON.setDailyRec((rdef != null) ? rdef.getIsDailyScheduleAllowed() : "false");
- wizardJSON.setDailyMFRec((rdef != null) ? rdef.getIsDailyMFScheduleAllowed() : "false");
- wizardJSON.setWeeklyRec((rdef != null) ? rdef.getIsWeeklyScheduleAllowed() : "false");
- wizardJSON.setMonthlyRec((rdef != null) ? rdef.getIsMonthlyScheduleAllowed() : "false");
- wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : "false");
+ wizardJSON.setOneTimeRec((rdef != null) ? rdef.getIsOneTimeScheduleAllowed() : FALSE);
+ wizardJSON.setHourlyRec((rdef != null) ? rdef.getIsHourlyScheduleAllowed() : FALSE);
+ wizardJSON.setDailyRec((rdef != null) ? rdef.getIsDailyScheduleAllowed() : FALSE);
+ wizardJSON.setDailyMFRec((rdef != null) ? rdef.getIsDailyMFScheduleAllowed() : FALSE);
+ wizardJSON.setWeeklyRec((rdef != null) ? rdef.getIsWeeklyScheduleAllowed() : FALSE);
+ wizardJSON.setMonthlyRec((rdef != null) ? rdef.getIsMonthlyScheduleAllowed() : FALSE);
+ wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : FALSE);
wizardJSON.setRepDefType(rdef.getReportDefType());
} else if(wizardJSON.getReportType().equals(AppConstants.RT_DASHBOARD)){
wizardJSON.setDashboardLayoutHTML((rdef != null) ? rdef.getCustomReport().getDashboardLayoutHTML() : null);
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java
index 04e237ae..86f2d912 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java
@@ -59,7 +59,7 @@ public class Scheduler extends TimerTask {
public void start() {
if (timeInterval > 0)
- timer.schedule(this, 0, timeInterval * 1000);
+ timer.schedule(this, 0, timeInterval * 1000L);
}
public void stop() {
@@ -92,18 +92,18 @@ public class Scheduler extends TimerTask {
sendNotifications.send_notification(AppUtils.getSMTPServer(), AppUtils.getSMTPServer(), Globals.getSystemName() ,
AppUtils.getDirectAccessURL(), timeInterval);
- } catch (Exception e) {
- Log.write("[SYSTEM ERROR Scheduler.run] Exception: " + e.getMessage());
- //e.printStackTrace();
- }
- finally {
-
- try {
- sendNotifications.deInit();
- } catch (SQLException e) {
- Log.write("[SYSTEM ERROR Scheduler.run] Could not close connection: " + e.getMessage());
- }
- }
+ } catch (Exception e) {
+ Log.write("[SYSTEM ERROR Scheduler.run] Exception: " + e.getMessage());
+ } finally {
+ try {
+ if (sendNotifications != null) {
+ sendNotifications.deInit();
+ }
+ } catch (SQLException e) {
+ Log.write("[SYSTEM ERROR Scheduler.run] Could not close connection: "
+ + e.getMessage());
+ }
+ }
} // run
} // Scheduler
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImpl.java
index 09fb374a..95ca3de7 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImpl.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImpl.java
@@ -127,7 +127,9 @@ public class LoginServiceCentralizedImpl extends FusionService implements LoginS
if (appuser == null && userHasRoleFunctions(user)) {
createUserIfNecessary(user);
} else {
- appuser.setLastLoginDate(new Date());
+ if(appuser != null) {
+ appuser.setLastLoginDate(new Date());
+ }
// update the last logged in date for the user
dataAccessService.saveDomainObject(appuser, additionalParams);