@Cacheable(value = "metadata-response", key = "#samlMetadataRequest.cacheableKey()")
    public SamlMetadataResponse resolveSamlMetadata(SamlMetadataRequest samlMetadataRequest) {
        LOGGER.info("Cache not found for saml-metadata {}", samlMetadataRequest.hashCode());

        Connection connection = connectionService.getConnectionByEntityId(samlMetadataRequest.getConnectionEntityId());

        MetadataResponseStatus metadataResponseStatus = null;
        nl.logius.digid.dc.domain.service.Service service = null;

        if (connection == null) {
            metadataResponseStatus = CONNECTION_NOT_FOUND;
        } else if (!connection.getStatus().isAllowed()) {
            metadataResponseStatus = CONNECTION_INACTIVE;
        } else if (!connection.getOrganization().getStatus().isAllowed()) {
            metadataResponseStatus = ORGANIZATION_INACTIVE;
        } else if (Boolean.FALSE.equals(connection.getOrganizationRole().getStatus().isAllowed())) {
            metadataResponseStatus = ORGANIZATION_ROLE_INACTIVE;
        } else {
            String serviceUUID = samlMetadataRequest.getServiceUuid() == null ? getServiceUUID(connection, samlMetadataRequest.getServiceEntityId(), samlMetadataRequest.getServiceIdx()) : samlMetadataRequest.getServiceUuid();
            samlMetadataRequest.setServiceUuid(serviceUUID);
            service = serviceService.serviceExists(connection, samlMetadataRequest.getServiceEntityId(), serviceUUID);
            if (service == null) {
                metadataResponseStatus = SERVICE_NOT_FOUND;
            } else if (!service.getStatus().isAllowed()) {
                metadataResponseStatus = SERVICE_INACTIVE;
            }
        }

        if (metadataResponseStatus != null) {
            return metadataResponseMapper.mapErrorResponse(metadataResponseStatus.name(), metadataResponseStatus.label);
        } else {
            String samlMetadata = generateReducedMetadataString(connection, service.getEntityId());
            return metadataResponseMapper.mapSuccessResponse(samlMetadata, connection, service, STATUS_OK.name());
        }
    }
@Test
    void organizationRoleInactiveTest() {
        Connection connection = newConnection(SAML_COMBICONNECT, true, true, false);
        when(connectionServiceMock.getConnectionByEntityId(anyString())).thenReturn(connection);
        SamlMetadataResponse response = metadataRetrieverServiceMock.resolveSamlMetadata(newMetadataRequest());

        assertEquals(ORGANIZATION_ROLE_INACTIVE.name(), response.getRequestStatus());
        assertEquals(ORGANIZATION_ROLE_INACTIVE.label, response.getErrorDescription());
    }