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

Refactored the getSysUserId Method into a Single Class #1303

Open
wants to merge 1 commit 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 @@ -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 {

// 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 @@ -28,6 +28,7 @@
import org.openelisglobal.common.services.StatusService.AnalysisStatus;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.ControllerUtills;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.common.util.IdValuePair;
import org.openelisglobal.common.util.LabelValuePair;
Expand Down Expand Up @@ -73,7 +74,7 @@

@Controller
@RequestMapping(value = "/rest/")
public class DisplayListController extends BaseRestController {
public class DisplayListController extends ControllerUtills {
@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.util.ControllerUtills;
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 ControllerUtills {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
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.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.ControllerUtills;
import org.openelisglobal.dataexchange.fhir.FhirConfig;
import org.openelisglobal.dataexchange.fhir.FhirUtil;
import org.openelisglobal.dataexchange.fhir.service.FhirTransformService;
Expand All @@ -49,7 +49,7 @@

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

@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.util.ControllerUtills;
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 ControllerUtills {

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.util.ControllerUtills;
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 ControllerUtills {

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.util;

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 {
import org.springframework.stereotype.Controller;

@Controller
public class ControllerUtills 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.util.ControllerUtills;
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 ControllerUtills {

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 @@ -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.util.ControllerUtills;
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 ControllerUtills {
@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.util.ControllerUtills;
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 ControllerUtills {

@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.util.ControllerUtills;
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 ControllerUtills {

@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.util.ControllerUtills;
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 ControllerUtills {

@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.util.ControllerUtills;
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 ControllerUtills {

@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.util.ControllerUtills;
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 ControllerUtills {

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 @@ -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.util.ControllerUtills;
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 ControllerUtills {

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
Loading
Loading