@Override
    public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor,
                                         EntityDescriptorIds entityDescriptorIds) {
        final ModelId modelId = entityDescriptor.id();
        final Optional<ViewDTO> optionalView = viewService.get(modelId.id());
        if (optionalView.isPresent()) {
            return Optional.of(exportNativeEntity(optionalView.get(), entityDescriptorIds));
        }
        LOG.debug("Couldn't find view {}", entityDescriptor);
        return Optional.empty();
    }
@Test
    @MongoDBFixtures("ViewFacadeTest.json")
    public void itShouldCreateAViewEntity() {
        final ViewDTO viewDTO = viewService.get(viewId)
                .orElseThrow(() -> new NotFoundException("Missing view with id: " + viewId));
        final EntityDescriptor searchDescriptor = EntityDescriptor.create(viewDTO.id(), ModelTypes.SEARCH_V1);
        final EntityDescriptor streamDescriptor = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1);
        final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(searchDescriptor, streamDescriptor);
        final Optional<Entity> optionalEntity = facade.exportEntity(searchDescriptor, entityDescriptorIds);

        assertThat(optionalEntity).isPresent();
        final Entity entity = optionalEntity.get();

        assertThat(entity).isInstanceOf(EntityV1.class);
        final EntityV1 entityV1 = (EntityV1) entity;
        assertThat(entityV1.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(searchDescriptor).orElse(null)));
        assertThat(entityV1.type()).isEqualTo(ModelTypes.SEARCH_V1);

        final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
        assertThat(viewEntity.title().asString()).isEqualTo(viewDTO.title());
        assertThat(viewEntity.type().toString()).isEqualTo(ViewDTO.Type.SEARCH.toString());

        assertThat(viewEntity.search().queries().size()).isEqualTo(1);
        final QueryEntity queryEntity = viewEntity.search().queries().iterator().next();
        assertThat(queryEntity.filter().filters().size()).isEqualTo(1);
        final StreamFilter filter = (StreamFilter) queryEntity.filter().filters().iterator().next();
        assertThat(filter.streamId()).doesNotMatch(streamId);
    }