@Test public void testListIntygWhenUserHasNoAssignments() { when(user.getIdsOfSelectedVardenhet()).thenReturn(Collections.<String>emptyList()); Response response = intygCtrl.listDraftsAndIntygForPerson(PNR.getPersonnummer()); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); verifyNoInteractions(intygService); verifyNoInteractions(mockUtkastRepository); }
@GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) { Personnummer personNummer = createPnr(personNummerIn); LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash()); SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer); if (patientSekretess == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service."); } WebCertUser user = getWebCertUserService().getUser(); authoritiesValidator.given(user) .privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient")); List<String> enhetsIds = getEnhetIdsForCurrentUser(); if (enhetsIds.isEmpty()) { LOG.error("Current user has no assignments"); return Response.status(Status.BAD_REQUEST).build(); } Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer); LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size()); List<Utkast> utkastList; if (authoritiesValidator.given(user).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST) .isVerified()) { Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG); utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus( DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper); LOG.debug("Got #{} utkast", utkastList.size()); } else { utkastList = Collections.emptyList(); } List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList); if (patientSekretess == SekretessStatus.TRUE) { Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering(); allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList()); } resourceLinkHelper.decorateIntygWithValidActionLinks(allIntyg, personNummer); Response.ResponseBuilder responseBuilder = Response.ok(allIntyg); if (intygItemListResponse.getRight()) { responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString()); } logService.logListIntyg(user, personNummer.getPersonnummerWithDash()); return responseBuilder.build(); }
IntygApiController extends AbstractApiController { @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) { Personnummer personNummer = createPnr(personNummerIn); LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash()); SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer); if (patientSekretess == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service."); } WebCertUser user = getWebCertUserService().getUser(); authoritiesValidator.given(user) .privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient")); List<String> enhetsIds = getEnhetIdsForCurrentUser(); if (enhetsIds.isEmpty()) { LOG.error("Current user has no assignments"); return Response.status(Status.BAD_REQUEST).build(); } Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer); LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size()); List<Utkast> utkastList; if (authoritiesValidator.given(user).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST) .isVerified()) { Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG); utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus( DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper); LOG.debug("Got #{} utkast", utkastList.size()); } else { utkastList = Collections.emptyList(); } List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList); if (patientSekretess == SekretessStatus.TRUE) { Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering(); allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList()); } resourceLinkHelper.decorateIntygWithValidActionLinks(allIntyg, personNummer); Response.ResponseBuilder responseBuilder = Response.ok(allIntyg); if (intygItemListResponse.getRight()) { responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString()); } logService.logListIntyg(user, personNummer.getPersonnummerWithDash()); return responseBuilder.build(); } }
IntygApiController extends AbstractApiController { @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) { Personnummer personNummer = createPnr(personNummerIn); LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash()); SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer); if (patientSekretess == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service."); } WebCertUser user = getWebCertUserService().getUser(); authoritiesValidator.given(user) .privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient")); List<String> enhetsIds = getEnhetIdsForCurrentUser(); if (enhetsIds.isEmpty()) { LOG.error("Current user has no assignments"); return Response.status(Status.BAD_REQUEST).build(); } Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer); LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size()); List<Utkast> utkastList; if (authoritiesValidator.given(user).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST) .isVerified()) { Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG); utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus( DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper); LOG.debug("Got #{} utkast", utkastList.size()); } else { utkastList = Collections.emptyList(); } List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList); if (patientSekretess == SekretessStatus.TRUE) { Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering(); allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList()); } resourceLinkHelper.decorateIntygWithValidActionLinks(allIntyg, personNummer); Response.ResponseBuilder responseBuilder = Response.ok(allIntyg); if (intygItemListResponse.getRight()) { responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString()); } logService.logListIntyg(user, personNummer.getPersonnummerWithDash()); return responseBuilder.build(); }  }
IntygApiController extends AbstractApiController { @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) { Personnummer personNummer = createPnr(personNummerIn); LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash()); SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer); if (patientSekretess == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service."); } WebCertUser user = getWebCertUserService().getUser(); authoritiesValidator.given(user) .privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient")); List<String> enhetsIds = getEnhetIdsForCurrentUser(); if (enhetsIds.isEmpty()) { LOG.error("Current user has no assignments"); return Response.status(Status.BAD_REQUEST).build(); } Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer); LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size()); List<Utkast> utkastList; if (authoritiesValidator.given(user).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST) .isVerified()) { Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG); utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus( DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper); LOG.debug("Got #{} utkast", utkastList.size()); } else { utkastList = Collections.emptyList(); } List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList); if (patientSekretess == SekretessStatus.TRUE) { Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering(); allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList()); } resourceLinkHelper.decorateIntygWithValidActionLinks(allIntyg, personNummer); Response.ResponseBuilder responseBuilder = Response.ok(allIntyg); if (intygItemListResponse.getRight()) { responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString()); } logService.logListIntyg(user, personNummer.getPersonnummerWithDash()); return responseBuilder.build(); }  @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn); @PUT @Path("/{intygsTyp}/{intygsId}/{version}/vidarebefordra") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) @PrometheusTimeMethod Response setNotifiedOnIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version, NotifiedState notifiedState); @PUT @Path("/{intygsTyp}/{intygsId}/{version}/redoattsignera") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) @PrometheusTimeMethod Response setKlarForSigneraAndSendStatusMessage(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version); @GET @Path("/{certificateId}/events") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getEventsForCertificate(@PathParam("certificateId") String certificateId); @GET @Path("/intygTypeVersion/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) Response getIntygTypeVersion(@PathParam("intygsId") String intygsId); @GET @Path("/allowToApprovedReceivers/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) Response getAllowToApprovedReceivers(@PathParam("intygsId") String intygsId); }
IntygApiController extends AbstractApiController { @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) { Personnummer personNummer = createPnr(personNummerIn); LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash()); SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer); if (patientSekretess == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service."); } WebCertUser user = getWebCertUserService().getUser(); authoritiesValidator.given(user) .privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient")); List<String> enhetsIds = getEnhetIdsForCurrentUser(); if (enhetsIds.isEmpty()) { LOG.error("Current user has no assignments"); return Response.status(Status.BAD_REQUEST).build(); } Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer); LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size()); List<Utkast> utkastList; if (authoritiesValidator.given(user).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST) .isVerified()) { Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG); utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus( DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper); LOG.debug("Got #{} utkast", utkastList.size()); } else { utkastList = Collections.emptyList(); } List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList); if (patientSekretess == SekretessStatus.TRUE) { Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering(); allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList()); } resourceLinkHelper.decorateIntygWithValidActionLinks(allIntyg, personNummer); Response.ResponseBuilder responseBuilder = Response.ok(allIntyg); if (intygItemListResponse.getRight()) { responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString()); } logService.logListIntyg(user, personNummer.getPersonnummerWithDash()); return responseBuilder.build(); }  @GET @Path("/person/{personNummer}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn); @PUT @Path("/{intygsTyp}/{intygsId}/{version}/vidarebefordra") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) @PrometheusTimeMethod Response setNotifiedOnIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version, NotifiedState notifiedState); @PUT @Path("/{intygsTyp}/{intygsId}/{version}/redoattsignera") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) @PrometheusTimeMethod Response setKlarForSigneraAndSendStatusMessage(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version); @GET @Path("/{certificateId}/events") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getEventsForCertificate(@PathParam("certificateId") String certificateId); @GET @Path("/intygTypeVersion/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) Response getIntygTypeVersion(@PathParam("intygsId") String intygsId); @GET @Path("/allowToApprovedReceivers/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @Consumes(MediaType.APPLICATION_JSON) Response getAllowToApprovedReceivers(@PathParam("intygsId") String intygsId);  }