Search in sources :

Example 1 with Metadata

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

the class FromCanonical method convert.

@NonNull
public Map<String, YTNodeTemplate> convert(TNodeTemplate node, @NonNull List<TRelationshipTemplate> rTs) {
    if (Objects.isNull(node)) {
        return new LinkedHashMap<>();
    }
    Metadata meta = new Metadata();
    if (Objects.nonNull(node.getX()) && Objects.nonNull(node.getY())) {
        meta.add(org.eclipse.winery.model.converter.support.Defaults.X_COORD, node.getX());
        meta.add(org.eclipse.winery.model.converter.support.Defaults.Y_COORD, node.getY());
    }
    if (Objects.nonNull(node.getName())) {
        meta.add(org.eclipse.winery.model.converter.support.Defaults.DISPLAY_NAME, node.getName());
    }
    return Collections.singletonMap(node.getIdFromIdOrNameField(), new YTNodeTemplate.Builder(convert(node.getType(), new NodeTypeId(node.getType()))).setProperties(convert(node.getProperties())).setMetadata(meta).setRequirements(convertRequirements(node.getRequirements())).setCapabilities(convert(node.getCapabilities())).setArtifacts(convert(node.getArtifacts())).build());
}
Also used : Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) LinkedHashMap(java.util.LinkedHashMap) YTNodeTemplate(org.eclipse.winery.model.tosca.yaml.YTNodeTemplate) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with Metadata

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

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

the class ReflectionTest method testServiceTemplates.

@ParameterizedTest
@MethodSource("getYamlFiles")
public void testServiceTemplates(Path fileName) throws Exception {
    Metadata metadata = getMetadata(fileName);
    String exception = metadata.get("exception");
    String assertValue = metadata.get("assert");
    String keyName = metadata.get("keyname");
    String assertTypeof = metadata.get("assert-typeof");
    testServiceTemplates(fileName, exception, keyName, assertValue, assertTypeof);
}
Also used : Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with Metadata

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

the class YamlBuilder method buildMetadata.

@Nullable
public Metadata buildMetadata(Object object) {
    if (Objects.isNull(object)) {
        return null;
    }
    @SuppressWarnings("unchecked") Map<String, Object> tmp = (Map<String, Object>) object;
    Metadata metadata = new Metadata();
    tmp.entrySet().stream().filter(entry -> Objects.nonNull(entry.getValue())).forEach(entry -> {
        metadata.put(entry.getKey(), stringValue(entry.getValue()));
        if (entry.getValue() instanceof Date) {
            SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSSZ");
            date.setTimeZone(TimeZone.getTimeZone("UTC"));
            metadata.put(entry.getKey(), date.format(entry.getValue()));
        }
    });
    return metadata;
}
Also used : YTRepositoryDefinition(org.eclipse.winery.model.tosca.yaml.YTRepositoryDefinition) YTGroupType(org.eclipse.winery.model.tosca.yaml.YTGroupType) YamlSpecKeywords(org.eclipse.winery.model.tosca.yaml.support.YamlSpecKeywords) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) Date(java.util.Date) YTPropertyAssignmentOrDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyAssignmentOrDefinition) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) YTMapPropertyFilterDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapPropertyFilterDefinition) YTStatusValue(org.eclipse.winery.model.tosca.yaml.YTStatusValue) YTTriggerDefinition(org.eclipse.winery.model.tosca.yaml.YTTriggerDefinition) YTNodeFilterDefinition(org.eclipse.winery.model.tosca.yaml.YTNodeFilterDefinition) 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) Nullable(org.eclipse.jdt.annotation.Nullable) YTRelationshipType(org.eclipse.winery.model.tosca.yaml.YTRelationshipType) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) YTListString(org.eclipse.winery.model.tosca.yaml.support.YTListString) YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) YTPolicyType(org.eclipse.winery.model.tosca.yaml.YTPolicyType) YTRelationshipTemplate(org.eclipse.winery.model.tosca.yaml.YTRelationshipTemplate) YTCapabilityAssignment(org.eclipse.winery.model.tosca.yaml.YTCapabilityAssignment) YTInterfaceAssignment(org.eclipse.winery.model.tosca.yaml.YTInterfaceAssignment) TimeZone(java.util.TimeZone) Predicate(java.util.function.Predicate) Set(java.util.Set) YTRelationshipDefinition(org.eclipse.winery.model.tosca.yaml.YTRelationshipDefinition) Credential(org.eclipse.winery.model.tosca.yaml.tosca.datatypes.Credential) YTTopologyTemplateDefinition(org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition) Collectors(java.util.stream.Collectors) YTInterfaceType(org.eclipse.winery.model.tosca.yaml.YTInterfaceType) YTPropertyAssignment(org.eclipse.winery.model.tosca.yaml.YTPropertyAssignment) Objects(java.util.Objects) YTEventFilterDefinition(org.eclipse.winery.model.tosca.yaml.YTEventFilterDefinition) YTRelationshipAssignment(org.eclipse.winery.model.tosca.yaml.YTRelationshipAssignment) List(java.util.List) Stream(java.util.stream.Stream) YTGroupDefinition(org.eclipse.winery.model.tosca.yaml.YTGroupDefinition) YTPropertyDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) VersionUtils(org.eclipse.winery.common.version.VersionUtils) YTRequirementAssignment(org.eclipse.winery.model.tosca.yaml.YTRequirementAssignment) YTCapabilityDefinition(org.eclipse.winery.model.tosca.yaml.YTCapabilityDefinition) Optional(java.util.Optional) YTAttributeAssignment(org.eclipse.winery.model.tosca.yaml.YTAttributeAssignment) QName(javax.xml.namespace.QName) YTPropertyFilterDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyFilterDefinition) NonNull(org.eclipse.jdt.annotation.NonNull) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) FieldValidator(org.eclipse.winery.repository.converter.validator.FieldValidator) YTSubstitutionMappings(org.eclipse.winery.model.tosca.yaml.YTSubstitutionMappings) YTMapObject(org.eclipse.winery.model.tosca.yaml.support.YTMapObject) YTParameterDefinition(org.eclipse.winery.model.tosca.yaml.YTParameterDefinition) YTCallOperationActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTCallOperationActivityDefinition) SimpleDateFormat(java.text.SimpleDateFormat) YTImplementation(org.eclipse.winery.model.tosca.yaml.YTImplementation) YTMapRequirementDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementDefinition) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) YTActivityDefinition(org.eclipse.winery.model.tosca.yaml.YTActivityDefinition) YTAttributeDefinition(org.eclipse.winery.model.tosca.yaml.YTAttributeDefinition) YTNodeTemplate(org.eclipse.winery.model.tosca.yaml.YTNodeTemplate) YTArtifactType(org.eclipse.winery.model.tosca.yaml.YTArtifactType) YTVersion(org.eclipse.winery.model.tosca.yaml.YTVersion) Pair(org.eclipse.collections.api.tuple.Pair) LinkedHashSet(java.util.LinkedHashSet) YTCapabilityType(org.eclipse.winery.model.tosca.yaml.YTCapabilityType) Logger(org.slf4j.Logger) YTOperationDefinition(org.eclipse.winery.model.tosca.yaml.YTOperationDefinition) YTMapPolicyDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapPolicyDefinition) YTEntityType(org.eclipse.winery.model.tosca.yaml.YTEntityType) YTSchemaDefinition(org.eclipse.winery.model.tosca.yaml.YTSchemaDefinition) Namespaces(org.eclipse.winery.model.converter.support.Namespaces) YTMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment) 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) InvalidToscaSyntax(org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) YTMapObject(org.eclipse.winery.model.tosca.yaml.support.YTMapObject) YTListString(org.eclipse.winery.model.tosca.yaml.support.YTListString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Metadata (org.eclipse.winery.model.tosca.yaml.support.Metadata)4 LinkedHashMap (java.util.LinkedHashMap)3 NonNull (org.eclipse.jdt.annotation.NonNull)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeZone (java.util.TimeZone)1 BiFunction (java.util.function.BiFunction)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 QName (javax.xml.namespace.QName)1 Pair (org.eclipse.collections.api.tuple.Pair)1