Skip to content

Commit 53e07f3

Browse files
committed
Added modifications droped by branch reset and fix for no session errors
- Included fix for no session errors in the backend - Included fix for pathogen related errors #13526
1 parent 45627d8 commit 53e07f3

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/user/CurrentUserService.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.ejb.LocalBean;
99
import javax.ejb.SessionContext;
1010
import javax.ejb.Stateless;
11-
import javax.enterprise.context.RequestScoped;
1211
import javax.persistence.EntityManager;
1312
import javax.persistence.PersistenceContext;
1413
import javax.persistence.TypedQuery;
@@ -23,16 +22,21 @@
2322

2423
import org.hibernate.Hibernate;
2524
import org.hibernate.proxy.HibernateProxy;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2627

2728
import de.symeda.sormas.api.audit.AuditIgnore;
2829
import de.symeda.sormas.api.user.UserRight;
30+
import de.symeda.sormas.backend.location.Location;
2931
import de.symeda.sormas.backend.util.ModelConstants;
3032

3133
@Stateless
3234
@LocalBean
3335
@AuditIgnore
3436
public class CurrentUserService {
3537

38+
private final Logger logger = LoggerFactory.getLogger(getClass());
39+
3640
@Resource
3741
private SessionContext context;
3842

@@ -50,7 +54,8 @@ public CurrentUserService() {
5054
*
5155
* @TransactionScoped would be better for performance, but is not supported by the CDI based testing framework
5256
*/
53-
@RequestScoped
57+
//@RequestScoped
58+
@Transactional(Transactional.TxType.REQUIRED)
5459
public User getCurrentUser() {
5560
final String currentUsername = context.getCallerPrincipal().getName();
5661

@@ -60,6 +65,8 @@ public User getCurrentUser() {
6065

6166
User cachedUser = userCache.get(currentUsername);
6267
if (cachedUser != null) {
68+
unProxyUserAddress(cachedUser);
69+
6370
return cachedUser;
6471
}
6572

@@ -73,6 +80,7 @@ public User getCurrentUser() {
7380
if (currentUser == null) {
7481
return null;
7582
} else {
83+
7684
userCache.put(currentUsername, currentUser);
7785
return currentUser;
7886
}
@@ -134,11 +142,28 @@ User fetchUser(String userName) {
134142
unproxy(currentUser.getPointOfEntry());
135143
unproxy(currentUser.getLaboratory());
136144
unproxy(currentUser.getAssociatedOfficer());
145+
146+
unProxyUserAddress(currentUser);
147+
137148
}
138149

139150
return currentUser;
140151
}
141152

153+
private void unProxyUserAddress(User currentUser) {
154+
if (currentUser.getAddress() != null) {
155+
Location deProxiedAddress = unproxy(currentUser.getAddress());
156+
deProxiedAddress.setContinent(unproxy(deProxiedAddress.getContinent()));
157+
deProxiedAddress.setSubcontinent(unproxy(deProxiedAddress.getSubcontinent()));
158+
deProxiedAddress.setCountry(unproxy(deProxiedAddress.getCountry()));
159+
deProxiedAddress.setRegion(unproxy(deProxiedAddress.getRegion()));
160+
deProxiedAddress.setDistrict(unproxy(deProxiedAddress.getDistrict()));
161+
deProxiedAddress.setCommunity(unproxy(deProxiedAddress.getCommunity()));
162+
deProxiedAddress.setFacility(unproxy(deProxiedAddress.getFacility()));
163+
currentUser.setAddress(deProxiedAddress);
164+
}
165+
}
166+
142167
public static <T> T unproxy(T proxied) {
143168
if (proxied instanceof HibernateProxy) {
144169
Hibernate.initialize(proxied);

sormas-ui/src/main/java/de/symeda/sormas/ui/samples/PathogenTestController.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Collectors;
3030

3131
import de.symeda.sormas.api.DiseaseHelper;
32+
import de.symeda.sormas.api.event.EventReferenceDto;
3233
import de.symeda.sormas.api.sample.PathogenTestType;
3334
import org.apache.commons.collections4.CollectionUtils;
3435

@@ -119,10 +120,25 @@ public CommitDiscardWrapperComponent<PathogenTestForm> getPathogenTestCreateComp
119120
int caseSampleCount,
120121
Consumer<PathogenTestDto> onSavedPathogenTest,
121122
boolean suppressNavigateToCase) {
122-
CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getByUuid(sampleDto.getAssociatedCase().getUuid());
123-
PathogenTestForm createForm = new PathogenTestForm(sampleDto, true, caseSampleCount, false, true, caseDataDto.getDisease()); // Valid because jurisdiction doesn't matter for entities that are about to be created
123+
// Pathogen tests can be created for a sample that is associated with a case, event participant or contact.
124+
Disease associatedEventOrCaseOrContactDisease = null;
125+
if (sampleDto.getAssociatedCase() != null) {
126+
CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getByUuid(sampleDto.getAssociatedCase().getUuid());
127+
associatedEventOrCaseOrContactDisease = caseDataDto.getDisease();
128+
}
129+
if (associatedEventOrCaseOrContactDisease == null && sampleDto.getAssociatedEventParticipant() != null) {
130+
EventParticipantDto eventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(sampleDto.getAssociatedEventParticipant().getUuid());
131+
EventReferenceDto eventDto = eventParticipant.getEvent();
132+
EventDto participantEvent = FacadeProvider.getEventFacade().getEventByUuid(eventDto.getUuid(), false);
133+
associatedEventOrCaseOrContactDisease = participantEvent.getDisease();
134+
}
135+
if (associatedEventOrCaseOrContactDisease == null && sampleDto.getAssociatedContact() != null) {
136+
ContactDto contact = FacadeProvider.getContactFacade().getByUuid(sampleDto.getAssociatedContact().getUuid());
137+
associatedEventOrCaseOrContactDisease = contact.getDisease();
138+
}
139+
PathogenTestForm createForm = new PathogenTestForm(sampleDto, true, caseSampleCount, false, true, associatedEventOrCaseOrContactDisease); // Valid because jurisdiction doesn't matter for entities that are about to be created
124140
// Defaulting the case disease as tested disease
125-
pathogenTest.setTestedDisease(caseDataDto.getDisease());
141+
pathogenTest.setTestedDisease(associatedEventOrCaseOrContactDisease);
126142
createForm.setValue(pathogenTest);
127143
final CommitDiscardWrapperComponent<PathogenTestForm> editView =
128144
new CommitDiscardWrapperComponent<>(createForm, UiUtil.permitted(UserRight.PATHOGEN_TEST_CREATE), createForm.getFieldGroup());

0 commit comments

Comments
 (0)