All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fivefaces.structureclient.config.SetupTestWorkflows Maven / Gradle / Ivy

There is a newer version: 1.0.62
Show newest version
package com.fivefaces.structureclient.config;

import com.fivefaces.setting.entity.Setting;
import com.fivefaces.setting.service.SettingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

@Profile("test")
@Component
@RequiredArgsConstructor
@Slf4j
public class SetupTestWorkflows {

    private final SettingService settingService;

    @Value("classpath:functions/step_functions.tf")
    private Resource terraformStepFunctions;

    @Value("classpath:functions")
    private Resource stepFunctionsFolder;

    @PostConstruct
    public void setup() {
        try {
            Setting setting = new Setting();
            setting.setId(144);
            setting.setName("Workflow AWS onPremise");
            final StringBuilder stepFunctions = new StringBuilder(Files.readString(Path.of(terraformStepFunctions.getURI())));
            try (Stream paths = Files.walk(Paths.get(stepFunctionsFolder.getURI()))) {
                paths.filter(Files::isRegularFile).forEach(file -> {
                        try {
                            if (file.getFileName().toString().startsWith("sf_")) {
                                stepFunctions.append(Files.readString(file)).append("\n");
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    });
            }
            setting.setValue(stepFunctions.toString());

            settingService.updateSetting(setting);
        } catch (IOException e) {
            log.error("Could not get JWKS private key", e);
        }


    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy