/*
 * (c) Copyright 2016 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 */
package io.cloudslang.lang.compiler.modeller;

import io.cloudslang.lang.compiler.modeller.model.Metadata;
import io.cloudslang.lang.compiler.parser.model.ParsedMetadata;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * User: bancl
 * Date: 1/12/2016
 */
@Component
public class MetadataModellerImpl implements MetadataModeller {

    @Override
    public Metadata createModel(ParsedMetadata parsedMetadata) {
        return transformToMetadata(parsedMetadata);
    }

    private Metadata transformToMetadata(ParsedMetadata parsedMetadata) {
        Metadata metadata = new Metadata();
        metadata.setDescription(parsedMetadata.getDescription());
        metadata.setInputs(convertMapListToMap(parsedMetadata.getInputs()));
        metadata.setOutputs(convertMapListToMap(parsedMetadata.getOutputs()));
        metadata.setResults(convertMapListToMap(parsedMetadata.getResults()));
        return metadata;
    }

    private Map<String, String> convertMapListToMap(List<Map<String, String>> mapList) {
        Map<String, String> inputs = new LinkedHashMap<>();
        for (Map<String,String> inputMap : mapList) {
            String key = inputMap.keySet().iterator().next();
            inputs.put(key, inputMap.get(key));
        }
        return inputs;
    }
}

@@ -1544,17 +1544,38 @@
     
-String ke
+Map.Entry%3CString, String%3E entr
 y = 
@@ -1583,18 +1583,20 @@
 nputMap.
-k
 e
+ntr
 ySet().i
@@ -1640,29 +1640,39 @@
 put(
-key, inputMap.get(key
+entry.getKey(), entry.getValue(
 ));%0A

support flow description YAML