Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor getSysUserId into a Separate Class #1272

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import org.openelisglobal.common.constants.Constants;
import org.openelisglobal.common.form.BaseForm;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.common.util.StringUtil;
import org.openelisglobal.common.util.SystemConfiguration;
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 SysUserId 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
Expand Up @@ -21,6 +21,7 @@
import org.openelisglobal.common.services.IStatusService;
import org.openelisglobal.common.services.StatusService;
import org.openelisglobal.common.services.StatusService.AnalysisStatus;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.DateUtil;
Expand Down Expand Up @@ -63,7 +64,7 @@

@Controller
@RequestMapping(value = "/rest/")
public class DisplayListController extends BaseRestController {
public class DisplayListController extends SysUserId {
@Value("${org.itech.login.saml:false}")
private Boolean useSAML;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.test.valueholder.Test;
import org.openelisglobal.typeofsample.service.TypeOfSampleService;
Expand All @@ -33,7 +33,7 @@

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

private TypeOfSampleService typeOfSampleService = SpringContext.getBean(TypeOfSampleService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalAndExternalWorker;
import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalWorker;
import org.openelisglobal.common.provider.query.workerObjects.PatientSearchWorker;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.rest.util.PatientSearchResultsPaging;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.dataexchange.fhir.FhirConfig;
Expand Down Expand Up @@ -49,7 +49,7 @@

@Controller
@RequestMapping(value = "/rest/")
public class PatientSearchRestController extends BaseRestController {
public class PatientSearchRestController extends SysUserId {

@Autowired
private FhirConfig fhirConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import org.openelisglobal.analysis.service.AnalysisService;
import org.openelisglobal.analysis.valueholder.Analysis;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.services.IStatusService;
import org.openelisglobal.common.services.StatusService;
import org.openelisglobal.common.servlet.validation.AjaxServlet;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.spring.util.SpringContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -37,7 +37,7 @@

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

private static final List<Integer> NOT_STARTED;
private static final List<Integer> TECH_REJECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.apache.commons.validator.GenericValidator;
import org.openelisglobal.common.action.IActionConstants;
import org.openelisglobal.common.constants.Constants;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.common.util.IdValuePair;
import org.openelisglobal.common.util.StringUtil;
import org.openelisglobal.login.valueholder.UserSessionData;
Expand All @@ -38,7 +38,7 @@

@Controller
@RequestMapping(value = "/rest/")
public class SampleEntryTestsForTypeProviderRestController extends BaseRestController {
public class SampleEntryTestsForTypeProviderRestController extends SysUserId {

private static String USER_TEST_SECTION_ID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.openelisglobal.common.rest;
package org.openelisglobal.common.userId;

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

@Component
public class BaseRestController implements IActionConstants {

public class SysUserId implements IActionConstants {
protected String getSysUserId(HttpServletRequest request) {
UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
if (usd == null) {
Expand All @@ -18,4 +17,5 @@ protected String getSysUserId(HttpServletRequest request) {
}
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.userId.SysUserId;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.dao.NotificationSubscriptionDAO;
import org.openelisglobal.notifications.entity.Notification;
Expand All @@ -31,7 +31,7 @@

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

private final NotificationDAO notificationDAO;
private final SystemUserService systemUserService;
Expand Down Expand Up @@ -210,15 +210,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 @@ -9,7 +9,7 @@
import org.hibernate.StaleObjectStateException;
import org.openelisglobal.common.exception.LIMSRuntimeException;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.dataexchange.fhir.exception.FhirPersistanceException;
import org.openelisglobal.dataexchange.fhir.exception.FhirTransformationException;
import org.openelisglobal.dataexchange.fhir.service.FhirTransformService;
Expand Down Expand Up @@ -37,7 +37,7 @@

@Controller
@RequestMapping(value = "/rest/")
public class PatientManagementRestController extends BaseRestController {
public class PatientManagementRestController extends SysUserId {
@Autowired
SearchResultsService searchService;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.GenericValidator;
import org.hl7.fhir.r4.model.Questionnaire;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.DisplayListService.ListType;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.dataexchange.fhir.FhirUtil;
import org.openelisglobal.dataexchange.fhir.exception.FhirLocalPersistingException;
import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService;
Expand All @@ -28,7 +28,7 @@

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

@Autowired
private FhirPersistanceService fhirPersistanceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.program.bean.CytologyDashBoardCount;
import org.openelisglobal.program.service.cytology.CytologyDisplayService;
import org.openelisglobal.program.service.cytology.CytologySampleService;
Expand All @@ -27,7 +27,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CytologyController extends BaseRestController {
public class CytologyController extends SysUserId {

@Autowired
private CytologySampleService cytologySampleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.program.bean.ImmunohistochemistryDashBoardCount;
import org.openelisglobal.program.service.ImmunohistochemistryDisplayService;
import org.openelisglobal.program.service.ImmunohistochemistrySampleService;
Expand All @@ -27,7 +27,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ImmunohistochemistryController extends BaseRestController {
public class ImmunohistochemistryController extends SysUserId {

@Autowired
private ImmunohistochemistrySampleService immunohistochemistrySampleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.rest.BaseRestController;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.program.bean.PathologyDashBoardCount;
import org.openelisglobal.program.service.PathologyDisplayService;
import org.openelisglobal.program.service.PathologySampleService;
Expand All @@ -27,7 +27,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PathologyController extends BaseRestController {
public class PathologyController extends SysUserId {

@Autowired
private PathologySampleService pathologySampleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.login.valueholder.UserSessionData;
import org.openelisglobal.common.userId.SysUserId;
import org.openelisglobal.patient.action.bean.PatientSearch;
import org.openelisglobal.qaevent.form.NonConformingEventForm;
import org.openelisglobal.qaevent.service.NCEventService;
Expand All @@ -26,7 +26,7 @@

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

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

Expand Down Expand Up @@ -91,14 +91,4 @@ public ResponseEntity<?> updateNCECorretiveActionForm(@RequestBody NonConforming
}
}

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 @@ -9,8 +9,8 @@
import org.openelisglobal.common.rest.bean.NceSampleItemInfo;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.RequesterService;
import org.openelisglobal.common.userId.SysUserId;
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 SysUserId {

private final SampleService sampleService;
private final SampleItemService sampleItemService;
Expand Down Expand Up @@ -175,17 +175,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 @@ -6,8 +6,8 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.userId.SysUserId;
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 SysUserId {

@Autowired
private NCEventService ncEventService;
Expand Down Expand Up @@ -120,15 +120,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());
}
}
Loading
Loading