Search in sources :

Example 1 with YTOperationDefinition

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

the class FromCanonical method convert.

public Map<String, YTInterfaceType> convert(TInterfaceType node) {
    if (Objects.isNull(node)) {
        return null;
    }
    Map<String, YTOperationDefinition> ops = new HashMap<>();
    node.getOperations().forEach((key, value) -> ops.putAll(convert(value)));
    YTInterfaceType.Builder interfaceBuilder = new YTInterfaceType.Builder().setDescription(node.getDescription()).setOperations(ops).setDerivedFrom(convert(node.getDerivedFrom(), node.getClass()));
    String typeName = node.getName();
    if (Objects.nonNull(node.getTargetNamespace()) && !node.getTargetNamespace().isEmpty()) {
        Metadata metadata = new Metadata();
        metadata.put("targetNamespace", node.getTargetNamespace());
        interfaceBuilder.addMetadata(metadata);
        if (Objects.nonNull(typeName)) {
            typeName = node.getTargetNamespace().concat(".").concat(typeName);
        }
    }
    return Collections.singletonMap(typeName, interfaceBuilder.build());
}
Also used : YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) YTInterfaceType(org.eclipse.winery.model.tosca.yaml.YTInterfaceType) Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata)

Example 2 with YTOperationDefinition

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

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

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

the class ToCanonical method convert.

private TOperationDefinition convert(YTOperationDefinition node, String id) {
    if (Objects.isNull(node)) {
        return null;
    }
    TOperationDefinition def = new TOperationDefinition();
    def.setId(id);
    def.setName(id);
    def.setDescription(node.getDescription());
    def.setInputs(convert(node.getInputs()));
    def.setOutputs(convert(node.getOutputs()));
    def.setImplementation(convert(node.getImplementation()));
    return def;
}
Also used : YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) TOperationDefinition(org.eclipse.winery.model.tosca.TOperationDefinition)

Example 5 with YTOperationDefinition

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

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