Search in sources :

Example 1 with YTImplementation

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

the class YamlRepository method addArtifactFileToTargetOperation.

/**
 * Adds artifacts filepath to interfaces for relationship type artifact templates
 *
 * @param interfaces interfaces of type
 * @param target     name of artifact
 * @param artifact   artifact
 * @return edited interfaces
 */
private YTInterfaceDefinition addArtifactFileToTargetOperation(YTInterfaceDefinition interfaces, YTArtifactDefinition artifact, String target) {
    Map<String, YTOperationDefinition> operations = interfaces.getOperations();
    for (Map.Entry<String, YTOperationDefinition> operation : operations.entrySet()) {
        if (operation.getKey().equalsIgnoreCase(target)) {
            YTImplementation implementation = operation.getValue().getImplementation();
            implementation.setPrimaryArtifactName(artifact.getFile());
            YTOperationDefinition operationDefinition = operation.getValue();
            operationDefinition.setImplementation(implementation);
            operation.setValue(operationDefinition);
        } else {
            YTOperationDefinition operationDefinition = operation.getValue();
            if (operationDefinition.getImplementation() != null) {
                if (operationDefinition.getImplementation().getPrimaryArtifactName() != null) {
                    if (operationDefinition.getImplementation().getPrimaryArtifactName().equalsIgnoreCase(target)) {
                        YTImplementation implementation = operationDefinition.getImplementation();
                        implementation.setPrimaryArtifactName(artifact.getFile());
                        operationDefinition.setImplementation(implementation);
                    }
                }
            }
            operation.setValue(operationDefinition);
        }
    }
    interfaces.setOperations(operations);
    return interfaces;
}
Also used : YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with YTImplementation

use of org.eclipse.winery.model.tosca.yaml.YTImplementation 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 3 with YTImplementation

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

the class ToCanonical method convert.

private TImplementation convert(YTImplementation node) {
    if (Objects.isNull(node)) {
        return null;
    }
    TImplementation def = new TImplementation();
    def.setPrimary(node.getPrimaryArtifactName());
    def.setDependencies(node.getDependencyArtifactNames());
    def.setTimeout(node.getTimeout());
    def.setOperationHost(node.getOperationHost());
    return def;
}
Also used : TImplementation(org.eclipse.winery.model.tosca.TImplementation) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation)

Example 4 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)

Example 5 with YTImplementation

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

the class YamlBuilder method buildOperationDefinition.

@Nullable
@SuppressWarnings("unchecked")
public YTOperationDefinition buildOperationDefinition(Object object, Parameter<YTOperationDefinition> parameter) {
    if (Objects.isNull(object) || !validate(YTOperationDefinition.class, object, parameter)) {
        return null;
    }
    if (!(object instanceof Map)) {
        return null;
    }
    Map<String, Object> map = (Map<String, Object>) object;
    String description = buildDescription(map.get(YamlSpecKeywords.DESCRIPTION));
    Map<String, YTParameterDefinition> inputs = buildParameterDefinitions(map.get(YamlSpecKeywords.INPUTS), new Parameter<>(parameter.getContext()).addContext(YamlSpecKeywords.INPUTS).setValue(parameter.getValue()));
    Map<String, YTParameterDefinition> outputs = buildParameterDefinitions(map.get(YamlSpecKeywords.OUTPUTS), new Parameter<>(parameter.getContext()).addContext(YamlSpecKeywords.OUTPUTS).setValue(parameter.getValue()));
    YTImplementation implementation = buildImplementation(map.get(YamlSpecKeywords.IMPLEMENTATION), new Parameter<YTImplementation>(parameter.getContext()).addContext(YamlSpecKeywords.IMPLEMENTATION));
    return new YTOperationDefinition.Builder().setDescription(description).setInputs(inputs).setOutputs(outputs).setImplementation(implementation).build();
}
Also used : YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) YTMapObject(org.eclipse.winery.model.tosca.yaml.support.YTMapObject) YTParameterDefinition(org.eclipse.winery.model.tosca.yaml.YTParameterDefinition) YTListString(org.eclipse.winery.model.tosca.yaml.support.YTListString) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Nullable(org.eclipse.jdt.annotation.Nullable)

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