public ProgressEvent handleRequest()

in aws-nimblestudio-studiocomponent/src/main/java/software/amazon/nimblestudio/studiocomponent/ReadHandler.java [21:92]


    public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        final CallbackContext callbackContext,
        final ProxyClient<NimbleClient> proxyClient,
        final Logger logger) {

        return proxy.initiate(
                "AWS-NimbleStudio-StudioComponent::Read",
                proxyClient,
                request.getDesiredResourceState(),
                callbackContext)
            .translateToServiceRequest(model -> GetStudioComponentRequest.builder()
                .studioId(model.getStudioId())
                .studioComponentId(model.getStudioComponentId())
                .build())
            .makeServiceCall((awsRequest, client) -> {
                try {
                    final GetStudioComponentResponse getStudioComponentResponse =
                            client.injectCredentialsAndInvokeV2(awsRequest,
                        client.client()::getStudioComponent);
                    final StudioComponentState state = getStudioComponentResponse.studioComponent().state();

                    if (StudioComponentState.DELETED.equals(state) || StudioComponentState.CREATE_FAILED.equals(state)) {
                        logger.log(String.format("%s [%s] is in state %s, unable to get resource",
                            ResourceModel.TYPE_NAME,
                            getStudioComponentResponse.studioComponent().studioComponentId(),
                            state.toString()));
                        throw new CfnNotFoundException(ResourceModel.TYPE_NAME,
                            getStudioComponentResponse.studioComponent().studioComponentId());
                    }

                    logger.log(String.format("%s [%s] read requested successfully", ResourceModel.TYPE_NAME,
                        getStudioComponentResponse.studioComponent().studioComponentId()));

                    return getStudioComponentResponse;
                } catch (final NimbleException e) {
                    logger.log(String.format("%s [%s] exception during read", ResourceModel.TYPE_NAME,
                        awsRequest.studioComponentId()));
                    throw ExceptionTranslator.translateToCfnException(e);
                }
            })
            .done(awsResponse -> {
                final ResourceModel.ResourceModelBuilder modelBuilder = ResourceModel.builder()
                    .studioId(request.getDesiredResourceState().getStudioId())
                    .configuration(Translator.toModelStudioComponentConfiguration(
                        awsResponse.studioComponent().configuration()))
                    .description(awsResponse.studioComponent().description())
                    .scriptParameters(awsResponse.studioComponent().scriptParameters().stream()
                        .map(sp -> ScriptParameterKeyValue.builder()
                            .key(sp.key())
                            .value(sp.value())
                            .build())
                    .collect(toList()))
                    .ec2SecurityGroupIds(awsResponse.studioComponent().ec2SecurityGroupIds())
                    .studioComponentId(awsResponse.studioComponent().studioComponentId())
                    .subtype(awsResponse.studioComponent().subtype().toString())
                    .type(awsResponse.studioComponent().type().toString())
                    .tags(awsResponse.studioComponent().tags());

                if (!StringUtils.isNullOrEmpty(awsResponse.studioComponent().name())) {
                    modelBuilder.name(awsResponse.studioComponent().name());
                }

                if (awsResponse.studioComponent().hasInitializationScripts()) {
                    modelBuilder.initializationScripts(
                        Translator.toModelStudioComponentInitializationScripts(awsResponse.studioComponent()));
                }

                return ProgressEvent.defaultSuccessHandler(modelBuilder.build());
            });
    }