class EnvironmentServiceDecorator {

    public void prepareEnvironmentsAndCredentialName(Set<StackViewV4Response> stackViewResponses, NameOrCrn nameOrCrn) {
        if (nameOrCrn.hasCrn()) {
            prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByCrn(nameOrCrn.getCrn()));
        } else if (nameOrCrn.hasName()) {
            prepareEnvironmentAndCredential(stackViewResponses, environmentClientService.getByName(nameOrCrn.getName()));
        } else {
            Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses();
            for (StackViewV4Response stackViewResponse : stackViewResponses) {
                Optional<SimpleEnvironmentResponse> first = responses.stream()
                        .filter(x -> x.getCrn().equals(stackViewResponse.getEnvironmentCrn()))
                        .findFirst();
                if (first.isPresent()) {
                    stackViewResponse.setCredentialName(first.get().getCredential().getName());
                    stackViewResponse.setEnvironmentName(first.get().getName());
                }
            }
        }

    }

}