@Test public void testWebcertUserIsNull() { when(webCertUserService.getUser()).thenReturn(null); Response response = statController.getStatistics(); assertNotNull(response); verify(webCertUserService).getUser(); assertEquals(OK, response.getStatus()); }
@GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); }
StatModuleApiController extends AbstractApiController { @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } }
StatModuleApiController extends AbstractApiController { @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); }  }
StatModuleApiController extends AbstractApiController { @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); }  @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getStatistics(); }
StatModuleApiController extends AbstractApiController { @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); }  @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getStatistics();  }