Search in sources :

Example 1 with YTInterfaceDefinition

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

the class YamlRepository method removeRelationshipArtifact.

/**
 * Deletes artifact from yaml relationship type
 *
 * @param relationshipType   TRelationshipType
 * @param targetArtifactName targeted artifact name
 * @return updated node type
 */
private YTRelationshipType removeRelationshipArtifact(YTRelationshipType relationshipType, String targetArtifactName) {
    Map<String, YTInterfaceDefinition> interfaces = relationshipType.getInterfaces();
    for (Map.Entry<String, YTInterfaceDefinition> interfaceDefinition : interfaces.entrySet()) {
        Map<String, YTOperationDefinition> operations = interfaceDefinition.getValue().getOperations();
        YTOperationDefinition operationWithImplementation = operations.get(targetArtifactName);
        if (operationWithImplementation != null) {
            operationWithImplementation.setImplementation(null);
            operations.replace(targetArtifactName, operationWithImplementation);
        } else {
            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) {
                            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);
        }
        relationshipType.setInterfaces(interfaces);
    }
    return relationshipType;
}
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)

Example 2 with YTInterfaceDefinition

use of org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition 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)

Example 3 with YTInterfaceDefinition

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

the class ToCanonical method convert.

private TInterfaceDefinition convert(YTInterfaceDefinition node, String id) {
    if (Objects.isNull(node)) {
        return null;
    }
    TInterfaceDefinition def = new TInterfaceDefinition();
    def.setId(id);
    def.setName(id);
    def.setType(node.getType());
    def.setInputs(convert(node.getInputs()));
    def.setOperations(convert(node.getOperations()));
    return def;
}
Also used : YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) TInterfaceDefinition(org.eclipse.winery.model.tosca.TInterfaceDefinition)

Example 4 with YTInterfaceDefinition

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

the class YamlReaderTest method testSupportedInterfaceDefinitions.

@Test
public void testSupportedInterfaceDefinitions() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/supported_interfaces.yml");
    YTServiceTemplate template = reader.parse(is);
    Assertions.assertNotNull(template);
    YTNodeType server = template.getNodeTypes().get("server");
    Assertions.assertEquals(2, server.getArtifacts().size());
    YTInterfaceDefinition standard = server.getInterfaces().get("Standard");
    Assertions.assertEquals(2, standard.getOperations().size());
    Assertions.assertEquals(1, standard.getInputs().size());
}
Also used : YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

YTInterfaceDefinition (org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition)4 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 YTImplementation (org.eclipse.winery.model.tosca.yaml.YTImplementation)2 YTOperationDefinition (org.eclipse.winery.model.tosca.yaml.YTOperationDefinition)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 TInterfaceDefinition (org.eclipse.winery.model.tosca.TInterfaceDefinition)1 YTNodeType (org.eclipse.winery.model.tosca.yaml.YTNodeType)1 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)1 AbstractConverterTest (org.eclipse.winery.repository.converter.AbstractConverterTest)1 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1