use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class FragaSvarResource method getWebCertUser.
// Create a fake WebCertUser which is authorized for the given care giver and unit
private WebCertUser getWebCertUser(String vardgivarId, String enhetsId) {
WebCertUser user = new WebCertUser();
Role role = authoritiesResolver.getRole(AuthoritiesConstants.ROLE_LAKARE);
user.setRoles(AuthoritiesResolverUtil.toMap(role));
user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
user.setHsaId("questionResource");
user.setNamn("questionResource");
user.setForskrivarkod("questionResource");
List<Vardgivare> vardgivarList = new ArrayList<>();
Vardgivare vardgivare = new Vardgivare(vardgivarId, "questionResource");
List<Vardenhet> vardenheter = new ArrayList<>();
Vardenhet enhet = new Vardenhet(enhetsId, "questionResource");
vardenheter.add(enhet);
vardgivare.setVardenheter(vardenheter);
vardgivarList.add(vardgivare);
user.setVardgivare(vardgivarList);
user.setValdVardgivare(vardgivare);
user.setValdVardenhet(enhet);
return user;
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class WebcertLoggingSessionRegistryImplTest method testRemoveSessionInformation.
@Test
public void testRemoveSessionInformation() throws Exception {
final String sessionId = "session-id";
final String hsaId = "hsa-id";
final String authenticationScheme = "authenticationScheme";
final String origin = "origin";
WebCertUser principal = mock(WebCertUser.class);
when(principal.getHsaId()).thenReturn(hsaId);
when(principal.getAuthenticationScheme()).thenReturn(authenticationScheme);
when(principal.getOrigin()).thenReturn(origin);
loggingSessionRegistry.registerNewSession(sessionId, principal);
loggingSessionRegistry.removeSessionInformation(sessionId);
verify(monitoringService).logUserLogout(hsaId, authenticationScheme);
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class IntygModuleApiController method createReplacementCopyRequest.
private CreateReplacementCopyRequest createReplacementCopyRequest(String orgIntygsId, String intygsTyp, CopyIntygRequest request) {
HoSPersonal hosPerson = createHoSPersonFromUser();
Patient patient = createPatientFromCopyIntygRequest(request);
final WebCertUser user = userService.getUser();
IntegrationParameters parameters = user.getParameters();
boolean coherentJournaling = parameters != null && parameters.isSjf();
CreateReplacementCopyRequest req = new CreateReplacementCopyRequest(orgIntygsId, intygsTyp, patient, hosPerson, coherentJournaling);
// Add new personnummer to request
addPersonnummerToRequest(req, parameters);
// Set djupintegrerad flag on request to true if origin is DJUPINTEGRATION
setDeepIntegrationFlagOnRequest(req);
return req;
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class IntygModuleApiController method createRenewal.
/**
* Create a copy that is a renewal of an existing certificate.
*
* @param request
* @param intygsTyp
* @param orgIntygsId
* @return
*/
@POST
@Path("/{intygsTyp}/{intygsId}/fornya")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
validateCopyAuthority(intygsTyp);
LOG.debug("Attempting to create a renewal of {} with id '{}'", intygsTyp, orgIntygsId);
WebCertUser user = userService.getUser();
boolean copyOkParam = user.getParameters() == null || user.getParameters().isCopyOk();
if (!copyOkParam) {
LOG.info("User is not allowed to request a copy for id '{}' due to false kopieraOK-parameter", orgIntygsId);
final String message = "Authorization failed due to false kopieraOK-parameter";
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, message);
}
if (!request.isValid()) {
LOG.error("Request to create renewal of '{}' is not valid", orgIntygsId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
}
CreateRenewalCopyRequest serviceRequest = createRenewalCopyRequest(orgIntygsId, intygsTyp, request);
CreateRenewalCopyResponse serviceResponse = copyUtkastService.createRenewalCopy(serviceRequest);
LOG.debug("Created a new draft with id: '{}' and type: {}, renewing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
return Response.ok().entity(response).build();
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class StatModuleApiController method getStatistics.
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getStatistics() {
StatsResponse statsResponse = new StatsResponse();
WebCertUser user = getWebCertUserService().getUser();
if (user == null) {
LOG.warn("getStatistics was called, but webcertUser was null!");
return Response.ok(statsResponse).build();
} else if (UserOriginType.DJUPINTEGRATION.name().equals(user.getOrigin())) {
LOG.debug("getStatistics was called, but webcertUser origin is DJUPINTEGRATION - returning empty answer");
return Response.ok(statsResponse).build();
}
List<String> allUnitIds = user.getIdsOfAllVardenheter();
if (allUnitIds == null || allUnitIds.isEmpty()) {
LOG.warn("getStatistics was called by user {} that have no id:s of vardenheter present in the user context: {}", user.getHsaId(), user.getAsJson());
return Response.ok(statsResponse).build();
}
Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
Map<String, Long> fragaSvarStatsMap = fragaSvarService.getNbrOfUnhandledFragaSvarForCareUnits(allUnitIds, intygsTyper);
Map<String, Long> arendeStatsMap = arendeService.getNbrOfUnhandledArendenForCareUnits(allUnitIds, intygsTyper);
Map<String, Long> mergedMap = mergeArendeAndFragaSvarMaps(fragaSvarStatsMap, arendeStatsMap);
Map<String, Long> intygStatsMap = intygDraftService.getNbrOfUnsignedDraftsByCareUnits(allUnitIds);
List<String> unitIdsOfSelected = user.getIdsOfSelectedVardenhet();
List<String> unitIdsOfNotSelected = new ArrayList<>(allUnitIds);
unitIdsOfNotSelected.removeAll(unitIdsOfSelected);
long fragaSvarOnOtherUnitThanTheSelected = calcSumFromSelectedUnits(unitIdsOfNotSelected, mergedMap);
statsResponse.setTotalNbrOfUnhandledFragaSvarOnOtherThanSelected(fragaSvarOnOtherUnitThanTheSelected);
long fragaSvarOnSelected = calcSumFromSelectedUnits(unitIdsOfSelected, mergedMap);
statsResponse.setTotalNbrOfUnhandledFragaSvarOnSelected(fragaSvarOnSelected);
long unsignedDraftsOnOtherThanSelected = calcSumFromSelectedUnits(unitIdsOfNotSelected, intygStatsMap);
statsResponse.setTotalNbrOfUnsignedDraftsOnOtherThanSelected(unsignedDraftsOnOtherThanSelected);
long unsignedDraftsOnSelected = getSafeStatValueFromMap(user.getValdVardenhet().getId(), intygStatsMap);
statsResponse.setTotalNbrOfUnsignedDraftsOnSelected(unsignedDraftsOnSelected);
populateStatsResponseWithVardgivarStats(statsResponse, user.getVardgivare(), intygStatsMap, mergedMap);
return Response.ok(statsResponse).build();
}
Aggregations