<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using Core.DomainModel;
using Core.DomainModel.ItSystem;
using Core.DomainServices;

namespace Core.ApplicationServices
{
    public class ItSystemService : IItSystemService
    {
        private readonly IGenericRepository<ItSystem> _repository;

        public ItSystemService(IGenericRepository<ItSystem> repository, IGenericRepository<AppType> appTypeRepository)
        {
            _repository = repository;
            InterfaceAppType = appTypeRepository.Get(appType => appType.Name == "Snitflade").Single();
        }

        public AppType InterfaceAppType { get; private set; }


        public IEnumerable<ItSystem> GetSystems(Organization organization, string nameSearch)
        {
            //TODO filter by organization or public

            if (nameSearch == null) return _repository.Get();

            return _repository.Get(system => system.Name.StartsWith(nameSearch));
        }

        public IEnumerable<ItSystem> GetNonInterfaces(Organization organization, string nameSearch)
        {
            return GetSystems(organization, nameSearch).Where(system => system.AppType.Id != InterfaceAppType.Id);
        }

        public IEnumerable<ItSystem> GetInterfaces(Organization organization, string nameSearch)
        {
            return GetSystems(organization, nameSearch).Where(system => system.AppType.Id == InterfaceAppType.Id);
        }

        public IEnumerable<ItSystem> GetHierarchy(int systemId)
        {
            var result = new List<ItSystem>();
            var system = _repository.GetByKey(systemId);         
            result.Add(system);
            result.AddRange(GetHierarchyChildren(system));
            result.AddRange(GetHierarchyParents(system));

            return result;
        }<commit_msg>Added check for optional AppType when fetching from DB<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using Core.DomainModel;
using Core.DomainModel.ItSystem;
using Core.DomainServices;

namespace Core.ApplicationServices
{
    public class ItSystemService : IItSystemService
    {
        private readonly IGenericRepository<ItSystem> _repository;

        public ItSystemService(IGenericRepository<ItSystem> repository, IGenericRepository<AppType> appTypeRepository)
        {
            _repository = repository;
            InterfaceAppType = appTypeRepository.Get(appType => appType.Name == "Snitflade").Single();
        }

        public AppType InterfaceAppType { get; private set; }


        public IEnumerable<ItSystem> GetSystems(Organization organization, string nameSearch)
        {
            //TODO filter by organization or public

            if (nameSearch == null) return _repository.Get();

            return _repository.Get(system => system.Name.StartsWith(nameSearch));
        }

        public IEnumerable<ItSystem> GetNonInterfaces(Organization organization, string nameSearch)
        {
            return GetSystems(organization, nameSearch).Where(system => system.AppType == null || system.AppType.Id != InterfaceAppType.Id);
        }

        public IEnumerable<ItSystem> GetInterfaces(Organization organization, string nameSearch)
        {
            return GetSystems(organization, nameSearch).Where(system => system.AppType != null && system.AppType.Id == InterfaceAppType.Id);
        }

        public IEnumerable<ItSystem> GetHierarchy(int systemId)
        {
            var result = new List<ItSystem>();
            var system = _repository.GetByKey(systemId);         
            result.Add(system);
            result.AddRange(GetHierarchyChildren(system));
            result.AddRange(GetHierarchyParents(system));

            return result;
        }
{'fraction_non_alphanumeric': 0.0858437749933351, 'fraction_numerical': 0.0, 'mean_word_length': 2.9124087591240877, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5889471', 'n_tokens_mistral': 953, 'n_tokens_neox': 923, 'n_words': 202}