Search in sources :

Example 6 with YTImplementation

use of org.eclipse.winery.model.tosca.yaml.YTImplementation in project winery by eclipse.

the class YamlRepository method removeImplementation.

/**
 * Deletes artifact from yaml node type interfaces
 *
 * @param nodeType           TNodeType
 * @param targetArtifactName targeted artifact name
 * @return updated node type
 */
private YTNodeType removeImplementation(YTNodeType nodeType, String targetArtifactName) {
    Map<String, YTInterfaceDefinition> interfaces = nodeType.getInterfaces();
    for (Map.Entry<String, YTInterfaceDefinition> interfaceDefinition : interfaces.entrySet()) {
        Map<String, YTOperationDefinition> operations = interfaceDefinition.getValue().getOperations();
        for (Map.Entry<String, YTOperationDefinition> operation : operations.entrySet()) {
            YTOperationDefinition operationDefinition = operation.getValue();
            if (operationDefinition != null) {
                YTImplementation implementation = operationDefinition.getImplementation();
                if (implementation != null) {
                    if (implementation.getPrimaryArtifactName() != null) {
                        // TODO
                        if (implementation.getPrimaryArtifactName().equalsIgnoreCase(targetArtifactName)) {
                            operationDefinition.setImplementation(null);
                        } else {
                            if (implementation.getDependencyArtifactNames() != null) {
                                List<String> names = implementation.getDependencyArtifactNames();
                                for (String name : implementation.getDependencyArtifactNames()) {
                                    if (name.equalsIgnoreCase(targetArtifactName)) {
                                        names.remove(name);
                                    }
                                }
                                implementation.setDependencyArtifactNames(names);
                            }
                        }
                    }
                    operationDefinition.setImplementation(implementation);
                }
                operation.setValue(operationDefinition);
            }
        }
        YTInterfaceDefinition tInterfaceDefinition = interfaceDefinition.getValue();
        tInterfaceDefinition.setOperations(operations);
        interfaceDefinition.setValue(tInterfaceDefinition);
    }
    nodeType.setInterfaces(interfaces);
    return nodeType;
}
Also used : YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

YTImplementation (org.eclipse.winery.model.tosca.yaml.YTImplementation)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 YTOperationDefinition (org.eclipse.winery.model.tosca.yaml.YTOperationDefinition)4 Nullable (org.eclipse.jdt.annotation.Nullable)2 YTInterfaceDefinition (org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition)2 YTListString (org.eclipse.winery.model.tosca.yaml.support.YTListString)2 YTMapObject (org.eclipse.winery.model.tosca.yaml.support.YTMapObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TImplementation (org.eclipse.winery.model.tosca.TImplementation)1 YTParameterDefinition (org.eclipse.winery.model.tosca.yaml.YTParameterDefinition)1