public String buildScript()

in src/main/java/com/epam/fonda/entity/configuration/orchestrator/MasterScript.java [73:113]


    public String buildScript(final Configuration configuration) {
        Map<String, String> variablesMap = initializeVariablesMap(configuration);
        Context context = new Context();
        context.setVariable("variablesMap", variablesMap);
        scriptsBySample.forEach((key, typeMap) -> {
            final List<String> sampleScripts = new LinkedList<>();
            if (typeMap.containsKey(ALIGNMENT) && typeMap.get(ALIGNMENT).size() > 1) {
                final List<String> alignments = typeMap.get(ALIGNMENT);
                final int lastScript = alignments.size() - 1;
                final List<String> replacedAlignmentScripts = alignments.stream()
                        .filter(StringUtils::isNotBlank)
                        .limit(lastScript)
                        .map(s -> s += AMPERSAND)
                        .collect(Collectors.toList());
                replacedAlignmentScripts.add(alignments.get(lastScript));
                typeMap.replace(ALIGNMENT, replacedAlignmentScripts);
            }
            processScripts(typeMap.getOrDefault(ALIGNMENT, Collections.emptyList()), sampleScripts);
            processScripts(typeMap.getOrDefault(POST_ALIGNMENT, Collections.emptyList()), sampleScripts);
            final List<String> secondaryScripts = typeMap.getOrDefault(SECONDARY, Collections.emptyList()).stream()
                    .filter(StringUtils::isNotBlank)
                    .map(s -> s += AMPERSAND)
                    .collect(Collectors.toList());

            List<String> baseScripts = replaceLast(sampleScripts, secondaryScripts);
            if (baseScripts.size() != 0) {
                alignmentScripts.add(new SampleScripts(baseScripts, secondaryScripts));
            }
        });
        context.setVariable("samplesProcessScripts", alignmentScripts);
        context.setVariable("postProcessScripts", postProcessScripts);
        String masterShell = TEMPLATE_ENGINE.process(MASTER_TEMPLATE, context);
        final String shellToSubmit = String.valueOf(variablesMap.get("shellToSubmit"));
        try {
            writeToFile(shellToSubmit, masterShell + cleanUpTmpDir(cleanupTempFiles),
                    configuration.getGlobalConfig().getPipelineInfo().getLineEnding());
        } catch (IOException e) {
            throw new IllegalArgumentException(format("Cannot create master %s file", shellToSubmit), e);
        }
        return shellToSubmit;
    }