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

com.regnosys.testing.pipeline.PipelineTreeConfig Maven / Gradle / Ivy

Go to download

Rune Testing is a java library that is utilised by Rosetta Code Generators and models expressed in the Rosetta DSL.

There is a newer version: 11.27.2
Show newest version
package com.regnosys.testing.pipeline;

/*-
 * ===============
 * Rune Testing
 * ===============
 * Copyright (C) 2022 - 2024 REGnosys
 * ===============
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ===============
 */

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import com.regnosys.rosetta.common.transform.TransformType;
import com.rosetta.model.lib.functions.RosettaFunction;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class PipelineTreeConfig {

    private ImmutableMap, String> xmlConfigMap;
    private ImmutableMap, String> xmlSchemaMap;
    private final List starting = new ArrayList<>();
    private PipelineTestPackFilter pipelineTestPackFilter;

    private final Multimap, TransformFunction> conf = ArrayListMultimap.create();
    private boolean strictUniqueIds;
    private Path writePath;

    public PipelineTreeConfig starting(TransformType transformType, Class function) {
        starting.add(new TransformFunction(function, transformType));
        return this;
    }

    public PipelineTreeConfig strictUniqueIds() {
        strictUniqueIds = true;
        return this;
    }

    public PipelineTreeConfig add(Class upstreamFunction, TransformType transformType, Class function) {
        TransformFunction current = new TransformFunction(function, transformType);
        conf.put(upstreamFunction, current);
        return this;
    }

    public PipelineTreeConfig withXmlConfigMap(ImmutableMap, String> xmlConfigMap) {
        this.xmlConfigMap = xmlConfigMap;
        return this;
    }

    public PipelineTreeConfig withXmlSchemaMap(ImmutableMap, String> xmlSchemaMap) {
        this.xmlSchemaMap = xmlSchemaMap;
        return this;
    }

    public ImmutableMap, String> getXmlConfigMap() {
        return Optional.ofNullable(xmlConfigMap).orElse(ImmutableMap.of());
    }

    public ImmutableMap, String> getXmlSchemaMap() {
        return xmlSchemaMap;
    }

    public PipelineTreeConfig withWritePath(Path writePath) {
        this.writePath = writePath;
        return this;
    }

    public Path getWritePath() {
        return writePath;
    }

    public boolean isStrictUniqueIds() {
        return strictUniqueIds;
    }

    List getStarting() {
        return starting;
    }

    public PipelineTreeConfig withTestPackFilter(PipelineTestPackFilter pipelineTestPackFilter) {
        this.pipelineTestPackFilter = pipelineTestPackFilter;
        return this;
    }

    PipelineTestPackFilter getTestPackFilter() {
        return pipelineTestPackFilter;
    }

    public List> getDownstreamFunctions(Class function) {
        Collection transformFunctions = conf.get(function);
        return transformFunctions.stream().map(TransformFunction::getFunction).collect(Collectors.toList());
    }

    public TransformType getDownstreamTransformType(Class function) {
        Collection transformFunctions = conf.get(function);
        return transformFunctions.stream().map(TransformFunction::getTransformType).findFirst().orElse(null);
    }

    static class TransformFunction {

        private final Class function;
        private final TransformType transformType;

        private TransformFunction(Class function, TransformType transformType) {
            this.function = function;
            this.transformType = transformType;
        }

        public Class getFunction() {
            return function;
        }

        public TransformType getTransformType() {
            return transformType;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy