Skip to content

Commit

Permalink
Merge pull request #1303 from Ariho-Seth/develop
Browse files Browse the repository at this point in the history
Refactored the getSysUserId Method into a Single Class
  • Loading branch information
mozzy11 authored Jan 8, 2025
2 parents af133c8 + c2e6dfe commit fb57bf7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.openelisglobal.common.form.BaseForm;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ControllerUtills;
import org.openelisglobal.common.util.StringUtil;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.login.dao.UserModuleService;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.view.PageBuilderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -28,7 +28,7 @@
import org.springframework.web.servlet.support.RequestContextUtils;

@Component
public abstract class BaseController implements IActionConstants {
public abstract class BaseController extends ControllerUtills implements IActionConstants {

// Request being autowired appears to be threadsafe because of how Spring
// handles autowiring, despite all controllers being singletons
Expand Down Expand Up @@ -183,17 +183,6 @@ protected void setPageTitles(HttpServletRequest request, BaseForm form) {
}
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}

protected void setSuccessFlag(HttpServletRequest request, boolean success) {
request.setAttribute(FWD_SUCCESS, success);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
package org.openelisglobal.common.rest;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.action.IActionConstants;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.common.util.ControllerUtills;
import org.springframework.stereotype.Component;

@Component
public class BaseRestController implements IActionConstants {
public class BaseRestController extends ControllerUtills implements IActionConstants {

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/openelisglobal/common/util/ControllerUtills.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.openelisglobal.common.util;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.action.IActionConstants;
import org.openelisglobal.login.valueholder.UserSessionData;

public class ControllerUtills {

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(IActionConstants.USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import nl.martijndwars.webpush.PushService;
import org.apache.http.HttpResponse;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.dao.NotificationSubscriptionDAO;
import org.openelisglobal.notifications.entity.Notification;
Expand All @@ -31,12 +31,11 @@

@RequestMapping("/rest")
@RestController
public class NotificationRestController {
public class NotificationRestController extends BaseRestController {

private final NotificationDAO notificationDAO;
private final SystemUserService systemUserService;
private final NotificationSubscriptionDAO notificationSubscriptionDAO;
private static final String USER_SESSION_DATA = "userSessionData";

@Autowired
private ConfigurableEnvironment env;
Expand Down Expand Up @@ -210,15 +209,4 @@ public ResponseEntity<?> unsubscribe(HttpServletRequest request) {

return ResponseEntity.ok().body("Unsubscribed successfully");
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.patient.action.bean.PatientSearch;
import org.openelisglobal.qaevent.form.NonConformingEventForm;
import org.openelisglobal.qaevent.service.NCEventService;
Expand All @@ -26,12 +26,10 @@

@RestController
@RequestMapping(value = "/rest")
public class NonConformingEventsCorrectionActionRestController {
public class NonConformingEventsCorrectionActionRestController extends BaseRestController {

private NCEventService ncEventService = SpringContext.getBean(NCEventService.class);

private static final String USER_SESSION_DATA = "userSessionData";

@Autowired
private NonConformingEventWorker nonConformingEventWorker;

Expand Down Expand Up @@ -90,15 +88,4 @@ public ResponseEntity<?> updateNCECorretiveActionForm(@RequestBody NonConforming
return ResponseEntity.ok().body(Map.of("success", false));
}
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.exception.LIMSInvalidConfigurationException;
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.rest.bean.NceSampleInfo;
import org.openelisglobal.common.rest.bean.NceSampleItemInfo;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.RequesterService;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.qaevent.form.NonConformingEventForm;
import org.openelisglobal.qaevent.service.NceCategoryService;
import org.openelisglobal.qaevent.valueholder.NcEvent;
Expand All @@ -33,7 +33,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ReportNonConformEventsRestController {
public class ReportNonConformEventsRestController extends BaseRestController {

private final SampleService sampleService;
private final SampleItemService sampleItemService;
Expand All @@ -42,8 +42,6 @@ public class ReportNonConformEventsRestController {
private final NceCategoryService nceCategoryService;
private final RequesterService requesterService;

private static final String USER_SESSION_DATA = "userSessionData";

@Autowired
private SystemUserService systemUserService;

Expand Down Expand Up @@ -175,17 +173,6 @@ private NceSampleInfo addSample(Sample sample) {
return sampleInfo;
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}

private Sample getSampleForLabNumber(String labNumber) throws LIMSInvalidConfigurationException {
return sampleService.getSampleByAccessionNumber(labNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.qaevent.form.NonConformingEventForm;
import org.openelisglobal.qaevent.service.NCEventService;
import org.openelisglobal.qaevent.service.NceCategoryService;
Expand All @@ -29,7 +29,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ViewNonConformEventsRestController {
public class ViewNonConformEventsRestController extends BaseRestController {

@Autowired
private NCEventService ncEventService;
Expand All @@ -46,8 +46,6 @@ public class ViewNonConformEventsRestController {
@Autowired
private SampleItemService sampleItemService;

private static final String USER_SESSION_DATA = "userSessionData";

private final NonConformingEventWorker nonConformingEventWorker;

public ViewNonConformEventsRestController(NonConformingEventWorker nonConformingEventWorker) {
Expand Down Expand Up @@ -120,15 +118,4 @@ public ResponseEntity<?> postReportNonConformingEvent(@RequestBody NonConforming
.body("An error occurred while processing the request." + e);
}
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA);
if (usd == null) {
return null;
}
}
return String.valueOf(usd.getSystemUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.openelisglobal.common.action.IActionConstants;
import org.openelisglobal.common.exception.LIMSRuntimeException;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.util.ControllerUtills;
import org.openelisglobal.common.validator.BaseErrors;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.patient.action.IPatientUpdate;
Expand All @@ -39,7 +40,7 @@

@Service
@Scope("prototype")
public class PatientManagementUpdate implements IPatientUpdate {
public class PatientManagementUpdate extends ControllerUtills implements IPatientUpdate {

private String currentUserId;
protected Patient patient;
Expand Down Expand Up @@ -78,11 +79,6 @@ public void initializeGlobalVariables() {
}
}

protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA);
return String.valueOf(usd.getSystemUserId());
}

public void setSysUserIdFromRequest(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA);
currentUserId = String.valueOf(usd.getSystemUserId());
Expand Down

0 comments on commit fb57bf7

Please sign in to comment.