Search in sources :

Example 1 with YTParameterDefinition

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

the class YamlBuilder method buildCallOperationActivityDefinition.

public YTActivityDefinition buildCallOperationActivityDefinition(Object object, Parameter<YTActivityDefinition> parameter) {
    if (Objects.isNull(object)) {
        return null;
    }
    try {
        // to support the short form notation
        if (object instanceof String) {
            return new YTCallOperationActivityDefinition((String) object);
        }
        Map<String, Object> map = (Map<String, Object>) object;
        YTCallOperationActivityDefinition callOperation = new YTCallOperationActivityDefinition(stringValue(map.get(YamlSpecKeywords.OPERATION)));
        Map<String, YTParameterDefinition> inputs = buildParameterDefinitions(map.get(YamlSpecKeywords.INPUTS), new Parameter<>(parameter.getContext()).addContext(YamlSpecKeywords.INPUTS).setValue(parameter.getValue()));
        callOperation.setInputs(inputs);
        return callOperation;
    } catch (ClassCastException e) {
        LOGGER.error("Unsupported format for the CallOperationActivityDefinition");
        LOGGER.error(e.getMessage());
        return null;
    }
}
Also used : YTCallOperationActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTCallOperationActivityDefinition) 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) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with YTParameterDefinition

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

Example 3 with YTParameterDefinition

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

the class FromCanonical method convert.

public YTMapActivityDefinition convert(TActivityDefinition node) {
    if (Objects.isNull(node)) {
        return null;
    }
    // TODO support other activity definition types
    if (node instanceof TCallOperationActivityDefinition) {
        TCallOperationActivityDefinition canonicalDef = (TCallOperationActivityDefinition) node;
        YTCallOperationActivityDefinition yamlDef = new YTCallOperationActivityDefinition(canonicalDef.getOperation());
        Map<String, YTParameterDefinition> inputs = canonicalDef.getInputs().stream().map(this::convert).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        yamlDef.setInputs(inputs);
        return new YTMapActivityDefinition().setMap(Collections.singletonMap(YamlSpecKeywords.CALL_OPERATION, yamlDef));
    }
    return new YTMapActivityDefinition();
}
Also used : TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) YTTriggerDefinition(org.eclipse.winery.model.tosca.yaml.YTTriggerDefinition) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) YTPolicyDefinition(org.eclipse.winery.model.tosca.yaml.YTPolicyDefinition) YTRequirementDefinition(org.eclipse.winery.model.tosca.yaml.YTRequirementDefinition) YTMapActivityDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapActivityDefinition) Map(java.util.Map) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) TActivityDefinition(org.eclipse.winery.model.tosca.TActivityDefinition) Constants(org.eclipse.winery.common.Constants) TImplementation(org.eclipse.winery.model.tosca.TImplementation) YTRelationshipDefinition(org.eclipse.winery.model.tosca.yaml.YTRelationshipDefinition) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) YTTopologyTemplateDefinition(org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) YTPropertyAssignment(org.eclipse.winery.model.tosca.yaml.YTPropertyAssignment) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) Stream(java.util.stream.Stream) YTGroupDefinition(org.eclipse.winery.model.tosca.yaml.YTGroupDefinition) YTPropertyDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition) TCapability(org.eclipse.winery.model.tosca.TCapability) YTRequirementAssignment(org.eclipse.winery.model.tosca.yaml.YTRequirementAssignment) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NonNull(org.eclipse.jdt.annotation.NonNull) TPolicy(org.eclipse.winery.model.tosca.TPolicy) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) YTSubstitutionMappings(org.eclipse.winery.model.tosca.yaml.YTSubstitutionMappings) Defaults(org.eclipse.winery.model.tosca.yaml.support.Defaults) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) YTNodeTemplate(org.eclipse.winery.model.tosca.yaml.YTNodeTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TSchema(org.eclipse.winery.model.tosca.TSchema) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) YTCapabilityType(org.eclipse.winery.model.tosca.yaml.YTCapabilityType) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) TDeploymentOrImplementationArtifact(org.eclipse.winery.model.tosca.TDeploymentOrImplementationArtifact) YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TCallOperationActivityDefinition(org.eclipse.winery.model.tosca.TCallOperationActivityDefinition) YTEntityType(org.eclipse.winery.model.tosca.yaml.YTEntityType) ParameterDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.ParameterDefinition) YTSchemaDefinition(org.eclipse.winery.model.tosca.yaml.YTSchemaDefinition) TOperation(org.eclipse.winery.model.tosca.TOperation) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TGroupDefinition(org.eclipse.winery.model.tosca.TGroupDefinition) YTGroupType(org.eclipse.winery.model.tosca.yaml.YTGroupType) YamlSpecKeywords(org.eclipse.winery.model.tosca.yaml.support.YamlSpecKeywords) YTPropertyAssignmentOrDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyAssignmentOrDefinition) LoggerFactory(org.slf4j.LoggerFactory) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) Nullable(org.eclipse.jdt.annotation.Nullable) YTRelationshipType(org.eclipse.winery.model.tosca.yaml.YTRelationshipType) TRequirement(org.eclipse.winery.model.tosca.TRequirement) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) AttributeDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.AttributeDefinition) YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) TTriggerDefinition(org.eclipse.winery.model.tosca.TTriggerDefinition) YTPolicyType(org.eclipse.winery.model.tosca.yaml.YTPolicyType) YTRelationshipTemplate(org.eclipse.winery.model.tosca.yaml.YTRelationshipTemplate) HashBiMap(org.eclipse.collections.impl.bimap.mutable.HashBiMap) YTCapabilityAssignment(org.eclipse.winery.model.tosca.yaml.YTCapabilityAssignment) TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) YTInterfaceType(org.eclipse.winery.model.tosca.yaml.YTInterfaceType) Objects(java.util.Objects) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) YTEventFilterDefinition(org.eclipse.winery.model.tosca.yaml.YTEventFilterDefinition) YTRelationshipAssignment(org.eclipse.winery.model.tosca.yaml.YTRelationshipAssignment) List(java.util.List) YamlExporter(org.eclipse.winery.repository.yaml.export.YamlExporter) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) YTCapabilityDefinition(org.eclipse.winery.model.tosca.yaml.YTCapabilityDefinition) Optional(java.util.Optional) TInterfaceDefinition(org.eclipse.winery.model.tosca.TInterfaceDefinition) YTParameterDefinition(org.eclipse.winery.model.tosca.yaml.YTParameterDefinition) YTCallOperationActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTCallOperationActivityDefinition) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation) YTMapRequirementDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementDefinition) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) YTAttributeDefinition(org.eclipse.winery.model.tosca.yaml.YTAttributeDefinition) TypeConverter(org.eclipse.winery.model.converter.support.xml.TypeConverter) ConstraintClauseKV(org.eclipse.winery.model.tosca.extensions.kvproperties.ConstraintClauseKV) TParameter(org.eclipse.winery.model.tosca.TParameter) YTArtifactType(org.eclipse.winery.model.tosca.yaml.YTArtifactType) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TEntityTypeImplementation(org.eclipse.winery.model.tosca.TEntityTypeImplementation) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) Logger(org.slf4j.Logger) TGroupType(org.eclipse.winery.model.tosca.TGroupType) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) TOperationDefinition(org.eclipse.winery.model.tosca.TOperationDefinition) TTag(org.eclipse.winery.model.tosca.TTag) TDataType(org.eclipse.winery.model.tosca.TDataType) Namespaces(org.eclipse.winery.model.converter.support.Namespaces) YTMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) YTConstraintClause(org.eclipse.winery.model.tosca.yaml.YTConstraintClause) YTDataType(org.eclipse.winery.model.tosca.yaml.YTDataType) Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) Collections(java.util.Collections) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) YTMapActivityDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapActivityDefinition) YTCallOperationActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTCallOperationActivityDefinition) YTParameterDefinition(org.eclipse.winery.model.tosca.yaml.YTParameterDefinition) TCallOperationActivityDefinition(org.eclipse.winery.model.tosca.TCallOperationActivityDefinition) YTCallOperationActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTCallOperationActivityDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashBiMap(org.eclipse.collections.impl.bimap.mutable.HashBiMap) HashMap(java.util.HashMap)

Example 4 with YTParameterDefinition

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

the class ToCanonical method convert.

private ParameterDefinition convert(YTParameterDefinition node, String name) {
    if (node == null) {
        return null;
    }
    ParameterDefinition p = new ParameterDefinition();
    p.setKey(name);
    p.setType(node.getType());
    p.setDescription(node.getDescription());
    p.setRequired(node.getRequired());
    p.setDefaultValue(ValueHelper.toString(node.getDefault()));
    p.setValue(ValueHelper.toString(node.getValue()));
    return p;
}
Also used : ParameterDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.ParameterDefinition) YTParameterDefinition(org.eclipse.winery.model.tosca.yaml.YTParameterDefinition)

Aggregations

YTParameterDefinition (org.eclipse.winery.model.tosca.yaml.YTParameterDefinition)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Nullable (org.eclipse.jdt.annotation.Nullable)2 ParameterDefinition (org.eclipse.winery.model.tosca.extensions.kvproperties.ParameterDefinition)2 YTImplementation (org.eclipse.winery.model.tosca.yaml.YTImplementation)2 YTOperationDefinition (org.eclipse.winery.model.tosca.yaml.YTOperationDefinition)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 QName (javax.xml.namespace.QName)1 HashBiMap (org.eclipse.collections.impl.bimap.mutable.HashBiMap)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Constants (org.eclipse.winery.common.Constants)1 Namespaces (org.eclipse.winery.model.converter.support.Namespaces)1