<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System;
using EAAddinFramework.Utilities;
using UML=TSF.UmlToolingFramework.UML;
using TSF.UmlToolingFramework.Wrappers.EA;
using FileHelpers;
using MP = MappingFramework;

namespace EAAddinFramework.Mapping
{
	/// <summary>
	/// Description of MappingFactory.
	/// </summary>
	public static class MappingFactory
	{
		public const string mappingSourcePathName = "mappingSourcePath";
        public const string mappingTargetPathName = "mappingTargetPath";
        public const string mappingLogicName = "mappingLogic";
        public static MappingSet createMappingSet(ElementWrapper sourceRoot, ElementWrapper targetRoot, MappingSettings settings )
        {
            //first create the root nodes
            var sourceRootNode = createNewRootNode(sourceRoot, settings);
            var targetRootNode = createNewRootNode(targetRoot, settings);
            //then create the new mappingSet
            var mappingSet = new MappingSet(sourceRootNode, targetRootNode, settings);
            return mappingSet;
        }
        public static ClassifierMappingNode createNewRootNode(ElementWrapper rootElement, MappingSettings settings)
        {
            //depending on the type of root we create a dataModel structure (Package) or a Message structure (class).
            return rootElement is Package ?
                    new ClassifierMappingNode(rootElement, settings, MP.ModelStructure.DataModel) :
                    new ClassifierMappingNode(rootElement, settings, MP.ModelStructure.Message);
        }
        public static MappingSet createMappingSet(ElementWrapper sourceRoot, MappingSettings settings)
        {
            //get target mapping root
            ElementWrapper targetRootElement = null;
            var packageTrace = sourceRoot.getRelationships<Abstraction>().FirstOrDefault(x => x.target is ElementWrapper && x.stereotypes.Any(y => y.name == "trace"));
            if (packageTrace != null) targetRootElement = packageTrace.target as ElementWrapper;
            return createMappingSet(sourceRoot, targetRootElement, settings);
        }

        private static List<string> getMappingPath(Element tagOwner, bool target)
        {
            var mappingPath = new List<String>();
            var taggedValue = target ? tagOwner.getTaggedValue(mappingTargetPathName) : tagOwner.getTaggedValue(mappingSourcePathName);
            if (taggedValue != null)
            {
                mappingPath = taggedValue.eaStringValue.Split('.').ToList();
            }
            return mappingPath;
        }
        private static List<string> getMappingPath(TaggedValue mappingTag, bool target)
        {
            var mappingPath = new List<String>();
            var pathString = target ? 
                KeyValuePairsHelper.getValueForKey(mappingTargetPathName, mappingTag.comment) : 
                KeyValuePairsHelper.getValueForKey(mappingSourcePathName, mappingTag.comment);
            if (! string.IsNullOrEmpty(pathString)) mappingPath = pathString.Split('.').ToList();
            return mappingPath;
        }

        private static List<string> getMappingPath(Element nodeSource, MappingNode targetRootNode)
        {
            if (nodeSource.owner == null || targetRootNode.source == null || nodeSource.uniqueID == targetRootNode.source.uniqueID) return new List<string>() { nodeSource.uniqueID };
            var path = getMappingPath((Element)nodeSource.owner, targetRootNode);
            path.Add(nodeSource.uniqueID);
            return path;
        }<commit_msg>fix order for traces<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System;
using EAAddinFramework.Utilities;
using UML=TSF.UmlToolingFramework.UML;
using TSF.UmlToolingFramework.Wrappers.EA;
using FileHelpers;
using MP = MappingFramework;

namespace EAAddinFramework.Mapping
{
	/// <summary>
	/// Description of MappingFactory.
	/// </summary>
	public static class MappingFactory
	{
		public const string mappingSourcePathName = "mappingSourcePath";
        public const string mappingTargetPathName = "mappingTargetPath";
        public const string mappingLogicName = "mappingLogic";
        public static MappingSet createMappingSet(ElementWrapper sourceRoot, ElementWrapper targetRoot, MappingSettings settings )
        {
            //first create the root nodes
            var sourceRootNode = createNewRootNode(sourceRoot, settings);
            var targetRootNode = createNewRootNode(targetRoot, settings);
            //then create the new mappingSet
            var mappingSet = new MappingSet(sourceRootNode, targetRootNode, settings);
            return mappingSet;
        }
        public static ClassifierMappingNode createNewRootNode(ElementWrapper rootElement, MappingSettings settings)
        {
            //depending on the type of root we create a dataModel structure (Package) or a Message structure (class).
            return rootElement is Package ?
                    new ClassifierMappingNode(rootElement, settings, MP.ModelStructure.DataModel) :
                    new ClassifierMappingNode(rootElement, settings, MP.ModelStructure.Message);
        }
        public static MappingSet createMappingSet(ElementWrapper sourceRoot, MappingSettings settings)
        {
            //get target mapping root
            ElementWrapper targetRootElement = null;
            var packageTrace = sourceRoot.getRelationships<Abstraction>().FirstOrDefault(x => x.source.uniqueID == sourceRoot.uniqueID
                                                                                        && x.target is ElementWrapper 
                                                                                        && x.stereotypes.Any(y => y.name == "trace"));
            if (packageTrace != null) targetRootElement = packageTrace.target as ElementWrapper;
            return createMappingSet(sourceRoot, targetRootElement, settings);
        }

        private static List<string> getMappingPath(Element tagOwner, bool target)
        {
            var mappingPath = new List<String>();
            var taggedValue = target ? tagOwner.getTaggedValue(mappingTargetPathName) : tagOwner.getTaggedValue(mappingSourcePathName);
            if (taggedValue != null)
            {
                mappingPath = taggedValue.eaStringValue.Split('.').ToList();
            }
            return mappingPath;
        }
        private static List<string> getMappingPath(TaggedValue mappingTag, bool target)
        {
            var mappingPath = new List<String>();
            var pathString = target ? 
                KeyValuePairsHelper.getValueForKey(mappingTargetPathName, mappingTag.comment) : 
                KeyValuePairsHelper.getValueForKey(mappingSourcePathName, mappingTag.comment);
            if (! string.IsNullOrEmpty(pathString)) mappingPath = pathString.Split('.').ToList();
            return mappingPath;
        }

        private static List<string> getMappingPath(Element nodeSource, MappingNode targetRootNode)
        {
            if (nodeSource.owner == null || targetRootNode.source == null || nodeSource.uniqueID == targetRootNode.source.uniqueID) return new List<string>() { nodeSource.uniqueID };
            var path = getMappingPath((Element)nodeSource.owner, targetRootNode);
            path.Add(nodeSource.uniqueID);
            return path;
        }
{'fraction_non_alphanumeric': 0.07830188679245283, 'fraction_numerical': 0.0, 'mean_word_length': 2.6448919449901767, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '921096', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1751, 'n_words': 445}