Example #1
0
        public void Index_GetSevenReposFromOrgWhereFourIsClonedLocallyOnlyLocallyClonedListed()
        {
            // Arrange
            Moq.Mock <IRepository> moqRepository = new Mock <IRepository>();

            Moq.Mock <ILogger <HomeController> >             moqLogger = new Mock <ILogger <HomeController> >();
            Moq.Mock <IHttpContextAccessor>                  moqHttpContextAccessor       = new Mock <IHttpContextAccessor>();
            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = new Mock <IOptions <ServiceRepositorySettings> >();
            Moq.Mock <IGitea> moqGiteaWrappeer = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddSevenReposForOrg1(moqGiteaWrappeer);

            Moq.Mock <ISourceControl> moqSourceControl = this.GetMoqSourceControlForIndexTest();

            RepositorySearch repositorySearch = new RepositorySearch();

            repositorySearch.OnlyLocalRepositories = true;

            AltinnCore.Designer.Controllers.HomeController controller = new AltinnCore.Designer.Controllers.HomeController(
                moqRepository.Object,
                moqLogger.Object,
                moqServiceRepositorySettings.Object,
                moqGiteaWrappeer.Object,
                moqHttpContextAccessor.Object,
                moqSourceControl.Object);

            // Act
            ActionResult result = controller.Index(repositorySearch);

            // Assert
            ViewResult            viewResult = Assert.IsType <ViewResult>(result);
            AltinnStudioViewModel model      = Assert.IsAssignableFrom <AltinnStudioViewModel>(viewResult.Model);

            Assert.Equal(4, model.Repositories.Count);
        }
Example #2
0
        public ActionResult Index(RepositorySearch repositorySearch)
        {
            AltinnStudioViewModel model       = new AltinnStudioViewModel();
            SearchResults         repositorys = _giteaApi.SearchRepository(repositorySearch.OnlyAdmin, repositorySearch.KeyWord, repositorySearch.Page).Result;

            if (repositorys != null)
            {
                model.Repositories = repositorys.Data;

                if (model.Repositories != null)
                {
                    foreach (Repository repo in model.Repositories)
                    {
                        repo.IsClonedToLocal = _sourceControl.IsLocalRepo(repo.Owner.Login, repo.Name);
                    }
                }
            }

            if (repositorySearch.OnlyLocalRepositories)
            {
                model.Repositories = model.Repositories.FindAll(r => r.IsClonedToLocal);
            }

            model.RepositorySearch = repositorySearch;

            // IList<OrgConfiguration> owners = _repository.GetOwners();
            return(View(model));
        }
Example #3
0
        public async Task GetMatchingRepositoriesWithSearchKey()
        {
            var go = new RepositorySearch("Key", new string[] { "insertGithubYourUserName", "insertyourGithubPassword" });
            await go.GetTopRatedReposLanguageCSharp();

            await go.GetTopRatedReposLanguageJavascript();

            go.GetMatch();
        }
Example #4
0
        public IList <IDictionary <string, object> > RepositorySearchForPolId(IDictionary <string, string> properties,
                                                                              IList <DateRange> dateRanges = null,
                                                                              ObjectStore objectStore      = P8ContentEngine.DefaultObjectStore,
                                                                              DocumentClass documentClass  = P8ContentEngine.DefaultDocumentClass,
                                                                              bool adminOverride           = false)
        {
            var whereClause = string.Concat(properties.Aggregate
                                            (
                                                string.Empty, (current, pt) => string.Concat
                                                (
                                                    current, string.Format
                                                    (
                                                        " AND '{1}' IN dc1.[{0}] ",
                                                        pt.Key,
                                                        pt.Value.Replace("'", "''")
                                                    )
                                                )
                                            ), BuildDateRangeSQL(dateRanges));

            var repositorySearch = new RepositorySearch
            {
                SearchScope = new ObjectStoreScope
                {
                    objectStore = objectStore.GetDescription()
                },
                SearchSQL = string.Format(
                    @"SELECT TOP 500 * FROM {0} dc1 WHERE {1}",
                    documentClass.GetDescription(),
                    Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase))
            };

            var searchResult = Search(repositorySearch, adminOverride);

            var repositoryResults = new List <IDictionary <string, object> >();

            if (searchResult != null && searchResult.Object != null)
            {
                repositoryResults.AddRange
                (
                    searchResult.Object.Select
                    (
                        o => o.Property.ToDictionary <PropertyType, string, object>
                        (
                            p => p.propertyId, Utilities.GetPropertyValue
                        )
                    )
                );
            }

            return(repositoryResults);
        }
Example #5
0
        public async Task <ActionResult <List <RepositoryDependencySearchResult> > > Get(string name, DateTime?asOf, string team, string topic, bool?hasContinuousDelivery)
        {
            var repositorySearch = new RepositorySearch
            {
                AsOf = asOf,
                HasContinuousDelivery = hasContinuousDelivery,
                Team  = team,
                Topic = topic
            };

            var dependencySearchResults = await dependencyManager.ReadAsync(name, repositorySearch).ConfigureAwait(false);

            return(dependencySearchResults);
        }
        public async Task <ActionResult <List <CountAggregationResult> > > GetAsync(
            string type,
            string team,
            string topic,
            bool?hasContinuousDelivery)
        {
            var repositorySearch = new RepositorySearch
            {
                TypeName = type,
                Team     = team,
                Topic    = topic,
                HasContinuousDelivery = hasContinuousDelivery,
            };


            var countAggregations = await repositoryImplementationsManager.SearchAsync(repositorySearch);

            return(countAggregations);
        }
        public void Search_SevenRepos()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddSevenReposForOrg1(moqGitea);
            Moq.Mock <ISourceControl> moqSourceControl = SourceControlMockHelper.GetMock();

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = new Mock <IOptions <ServiceRepositorySettings> >();
            Moq.Mock <IRepository>          moqRepository          = new Mock <IRepository>();
            Moq.Mock <IHttpContextAccessor> moqHttpContextAccessor = new Mock <IHttpContextAccessor>();

            AltinnCore.Designer.Controllers.RepositoryController controller = new AltinnCore.Designer.Controllers.RepositoryController(moqGitea.Object, moqServiceRepositorySettings.Object, moqSourceControl.Object, moqRepository.Object, moqHttpContextAccessor.Object);
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            List <Repository> result = controller.Search(repositorySearch);

            // Assert
            Assert.Equal(7, result.Count);
        }
Example #8
0
        public void Current_LoggedInUser()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.GetCurrentUser_ReturnsOne(moqGitea);

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();

            AltinnCore.Designer.Controllers.UserController controller = new AltinnCore.Designer.Controllers.UserController(moqGitea.Object, moqServiceRepositorySettings.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556")
            };
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            User result = controller.Current();

            // Assert
            Assert.NotNull(result);
        }
        public async Task <List <CountAggregationResult> > SearchAsync(RepositorySearch repositorySearch)
        {
            var dbConnection = repositoryAnalysisContext.Database.GetDbConnection();

            var countAggregationResults = await dbConnection.QueryAsync <CountAggregationResult>(
                @"select RI.name, Count(*)
                    FROM repository_implementation RI
                    join repository_type_and_implementations RTI
                        on RTI.repository_type_and_implementations_id = RI.repository_type_and_implementations_id
                    join repository_snapshot RS
                        on RS.repository_snapshot_id = RTI.repository_snapshot_id
                            -- This will cause only the current state of the repositories to be included in the results
                        and RS.window_ends_on is null
                    where RTI.type_name = @RepositoryTypeName
                    group by RI.name
                    order by count desc",
                new { RepositoryTypeName = repositorySearch.TypeName });

            return(countAggregationResults.AsList());
        }
Example #10
0
        public async Task <List <IntervalCountAggregations> > SearchAsync(RepositorySearch repositorySearch, IntervalInfo intervalInfo)
        {
            var intervalCountAggregations = new List <IntervalCountAggregations>();

            if (intervalInfo.Intervals.HasValue && intervalInfo.Intervals.Value > 1)
            {
                if (!intervalInfo.IntervalEndTime.HasValue)
                {
                    intervalInfo.IntervalEndTime = DateTime.Now;
                }

                var intervalTimeSpan = (intervalInfo.IntervalEndTime.Value - intervalInfo.IntervalStartTime.Value) / intervalInfo.Intervals.Value;

                var searchTasks = new List <Task <IntervalCountAggregations> >();

                for (int i = 0; i < intervalInfo.Intervals.Value; i++)
                {
                    DateTime?intervalCreatedOnOrAfter  = intervalInfo.IntervalStartTime.Value.Add(intervalTimeSpan * i);
                    DateTime?intervalCreatedOnOrBefore = intervalCreatedOnOrAfter.Value.Add(intervalTimeSpan);

                    var searchTask = repositoryImplementationsRepository.SearchAsync(repositorySearch, intervalCreatedOnOrAfter, intervalCreatedOnOrBefore);

                    searchTasks.Add(searchTask);
                }

                await Task.WhenAll(searchTasks).ConfigureAwait(false);

                foreach (var task in searchTasks)
                {
                    intervalCountAggregations.Add(task.Result);
                }
            }
            else
            {
                var intervalCountAggregation = await repositoryImplementationsRepository.SearchAsync(repositorySearch, intervalInfo.IntervalStartTime, intervalInfo.IntervalEndTime).ConfigureAwait(false);

                intervalCountAggregations.Add(intervalCountAggregation);
            }

            return(intervalCountAggregations);
        }
Example #11
0
        public IList <IDictionary <string, object> > Search(RepositorySearch request, IList <string> properties)
        {
            var searchResponse = Search(request);

            var searchResults = new List <IDictionary <string, object> >();

            if (searchResponse != null && searchResponse.Object != null)
            {
                searchResults.AddRange
                (
                    searchResponse.Object.Select
                    (
                        o => o.Property.ToDictionary <PropertyType, string, object>
                        (
                            p => p.propertyId, Utilities.GetPropertyValue
                        )
                    )
                );
            }

            return(searchResults);
        }
        public async Task <ActionResult <List <IntervalCountAggregations> > > GetAsync(
            string type,
            string team,
            string topic,
            bool?hasContinuousDelivery,
            DateTime?asOf,
            DateTime?intervalStartTime,
            DateTime?intervalEndTime,
            int?intervals)
        {
            if (intervals.HasValue && (!intervalStartTime.HasValue && !intervalEndTime.HasValue))
            {
                var modelStateDictionary = new ModelStateDictionary();
                modelStateDictionary.TryAddModelError(nameof(intervals), "Can not specify an interval without a start or end time");

                return(BadRequest(modelStateDictionary));
            }

            var repositorySearch = new RepositorySearch
            {
                TypeName = type,
                Team     = team,
                Topic    = topic,
                HasContinuousDelivery = hasContinuousDelivery,
                AsOf = asOf
            };

            var intervalInfo = new IntervalInfo
            {
                IntervalStartTime = intervalStartTime,
                IntervalEndTime   = intervalEndTime,
                Intervals         = intervals
            };

            var intervalCountAggregations = await repositoryImplementationsManager.SearchAsync(repositorySearch, intervalInfo);

            return(intervalCountAggregations);
        }
Example #13
0
        public void Organization_GetOrg_Valid()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddOneOrg(moqGitea);
            Moq.Mock <ISourceControl> moqSourceControl = SourceControlMockHelper.GetMock();

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();
            Moq.Mock <IRepository>          moqRepository          = new Mock <IRepository>();
            Moq.Mock <IHttpContextAccessor> moqHttpContextAccessor = new Mock <IHttpContextAccessor>();

            AltinnCore.Designer.Controllers.RepositoryController controller = new AltinnCore.Designer.Controllers.RepositoryController(moqGitea.Object, moqServiceRepositorySettings.Object, moqSourceControl.Object, moqRepository.Object, moqHttpContextAccessor.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556", false)
            };
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            ActionResult <Organization> result = controller.Organization("MockOrg");

            // Assert
            Assert.NotNull(result.Value);
        }
Example #14
0
        public IList <IDictionary <string, object> > ContentSearch(string keywords,
                                                                   IDictionary <string, string> properties = null,
                                                                   IList <DateRange> dateRanges            = null,
                                                                   ObjectStore objectStore     = P8ContentEngine.DefaultObjectStore,
                                                                   DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass,
                                                                   bool adminOverride          = false)
        {
            var whereClause = string.Concat(properties != null
                                ? Regex.Replace(properties.Aggregate
                                                (
                                                    string.Empty, (current, pt) => string.Concat
                                                    (
                                                        current, string.Format
                                                        (
                                                            " AND dc1.[{0}] LIKE '%{1}%'",
                                                            pt.Key,
                                                            pt.Value.Replace("'", "''")
                                                        )
                                                    )
                                                ), @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase)
                                : string.Empty, BuildDateRangeSQL(dateRanges));

            var contentSearch = new RepositorySearch
            {
                SearchScope = new ObjectStoreScope
                {
                    objectStore = objectStore.GetDescription()
                },
                SearchSQL = string.Format(
                    @"SELECT TOP 500 cs.*, dc1.*
						FROM {0} dc1 INNER JOIN ContentSearch cs ON dc1.This = cs.QueriedObject
						WHERE CONTAINS(dc1.*, '{1}') {2}
						ORDER BY cs.Rank DESC
						OPTIONS (FULLTEXTROWLIMIT 500)"                        ,
                    documentClass.GetDescription(),
                    keywords.Replace("'", "''"),
                    !string.IsNullOrEmpty(whereClause)
                                        ? string.Format("AND ({0})", whereClause) : string.Empty)
            };

//			var contentSearch = new RepositorySearch
//			{
//				SearchScope = new ObjectStoreScope
//				{
//					objectStore = objectStore.GetDescription()
//				},
//				SearchSQL = string.Format(
//					@"SELECT TOP 500 *
//						FROM ({0} dc1 INNER JOIN ContentSearch cs ON dc1.This = cs.QueriedObject)
//						RIGHT OUTER JOIN {0} dc2 ON dc1.ID = dc2.ID
//						WHERE CONTAINS(dc1.*, '{1}')
//						AND ({2})
//						OR (dc1.ID = dc2.RelatedDocumentID OR dc1.RelatedDocumentID = dc2.RelatedDocumentID)
//						ORDER BY cs.Rank DESC
//						OPTIONS (FULLTEXTROWLIMIT 500)",
//					documentClass.GetDescription(),
//					keywords.Replace("'", "''"),
//					Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase))
//			};

            var searchResults = Search(contentSearch, adminOverride);

            var contentResults = new List <IDictionary <string, object> >();

            if (searchResults != null && searchResults.Object != null)
            {
                foreach (var searchResult in searchResults.Object)
                {
                    var dmsProperties = new Dictionary <string, object>();

                    foreach (var dmsProperty in searchResult.Property
                             .Where
                             (
                                 p => !dmsProperties.ContainsKey(p.propertyId)
                             ))
                    {
                        dmsProperties.Add(dmsProperty.propertyId, Utilities.GetPropertyValue(dmsProperty));
                    }

                    contentResults.Add(dmsProperties);
                }
            }

            return(contentResults);
        }
Example #15
0
 public IList <IDictionary <string, object> > Search(RepositorySearch request, string property) => Search(request, new List <string> {
     property
 });
        public async Task <List <string> > SearchAsync(RepositorySearch repositorySearch)
        {
            var repositoryNames = await repositoryRepository.SearchAsync(repositorySearch).ConfigureAwait(false);

            return(repositoryNames);
        }
        public async Task <List <RepositoryModel> > Search(RepositorySearch repositorySearch)
        {
            SearchResults repositories = await _giteaApi.SearchRepository(repositorySearch.OnlyAdmin, repositorySearch.KeyWord, repositorySearch.Page);

            return(repositories.Data);
        }
Example #18
0
        public async Task <List <string> > SearchAsync(RepositorySearch repositorySearch)
        {
            var query = @"
            select rcs.name
            from repository_current_state as rcs
            join repository_team as rt
              on rt.repository_current_state_id = rcs.repository_current_state_id
            join repository_snapshot as rs
              on rs.repository_current_state_id = rcs.repository_current_state_id
            join repository_type_and_implementations as rti 
              on rti.repository_snapshot_id = rs.repository_snapshot_id
            join repository_implementation as ri 
              on ri.repository_type_and_implementations_id = rti.repository_type_and_implementations_id
            join repository_dependency as rd
              on rd.repository_snapshot_id = rs.repository_snapshot_id
              {{DEPENDENCY_JOIN}}
            where 1=1
            {{WHERE_CLAUSES}}
            group by rcs.name
            order by rcs.name
            ";

            var whereClausesStringBuilder = new StringBuilder();

            if (!repositorySearch.AsOf.HasValue)
            {
                whereClausesStringBuilder.AppendLine("and rs.window_ends_on is null");
            }

            if (repositorySearch.HasContinuousDelivery.HasValue)
            {
                whereClausesStringBuilder.AppendLine($"and rcs.continuous_delivery = {repositorySearch.HasContinuousDelivery.ToString()}");
            }

            if (!string.IsNullOrWhiteSpace(repositorySearch.Team))
            {
                whereClausesStringBuilder.AppendLine($"and rt.name = '{repositorySearch.Team}'");
            }

            if (!string.IsNullOrWhiteSpace(repositorySearch.TeamPermissions))
            {
                whereClausesStringBuilder.AppendLine($"and rt.permission = '{repositorySearch.TeamPermissions}'");
            }

            if (!string.IsNullOrWhiteSpace(repositorySearch.TypeName))
            {
                whereClausesStringBuilder.AppendLine($"and rti.type_name = '{repositorySearch.TypeName}'");
            }

            query = query.Replace("{{DEPENDENCY_JOIN}}", BuildDependenciesJoin());

            query = query.Replace("{{WHERE_CLAUSES}}", whereClausesStringBuilder.ToString());

            var dbConnection = repositoryAnalysisContext.Database.GetDbConnection();

            var repositoryNames = await dbConnection.QueryAsync <string>(query);

            return(repositoryNames.AsList());

            string GetRangeSpecifierString(RangeSpecifier rangeSpecifier)
            {
                switch (rangeSpecifier)
                {
                case RangeSpecifier.GreaterThan:
                    return(">");

                case RangeSpecifier.GreaterThanOrEqualTo:
                    return(">=");

                case RangeSpecifier.LessThan:
                    return("<");

                case RangeSpecifier.LessThanOrEqualTo:
                    return("<=");

                case RangeSpecifier.EqualTo:
                    return("=");

                default:
                    return(null);
                }
            }

            string BuildDependenciesJoin()
            {
                if (repositorySearch.Dependencies.Any())
                {
                    var depdendencyJoinStringBuilder = new StringBuilder();
                    depdendencyJoinStringBuilder.AppendLine("and rd.repository_snapshot_id in (");

                    var dependenciesAdded = 0;

                    foreach (var dependency in repositorySearch.Dependencies)
                    {
                        if (dependenciesAdded > 0)
                        {
                            depdendencyJoinStringBuilder.AppendLine("intersect");
                        }

                        depdendencyJoinStringBuilder.AppendLine("select repository_snapshot_id");
                        depdendencyJoinStringBuilder.AppendLine("from public.repository_dependency");
                        depdendencyJoinStringBuilder.AppendLine($"where name ilike '{dependency.Name}'");

                        if (!string.IsNullOrWhiteSpace(dependency.Version))
                        {
                            var paddedVersion = versionManager.GetPaddedVersion(dependency.Version);

                            var rangeSpecifierText = GetRangeSpecifierString(dependency.RangeSpecifier);

                            depdendencyJoinStringBuilder.AppendLine($"and padded_version {rangeSpecifierText} '{paddedVersion}'");
                        }

                        dependenciesAdded++;
                    }

                    depdendencyJoinStringBuilder.AppendLine(")");

                    return(depdendencyJoinStringBuilder.ToString());
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
 public async Task<List<RepositoryDependencySearchResult>> ReadAsync(string name, RepositorySearch repositorySearch)
 {
     return await dependencyRepository.ReadAsync(name, repositorySearch).ConfigureAwait(false);
 }
Example #20
0
        public ObjectSetType Search(RepositorySearch request, bool adminOverride = false)
        {
            InitialiseToken(adminOverride);

            return(Service.ExecuteSearch(request));
        }
Example #21
0
        public async Task <ActionResult <List <string> > > GetAsync(
            string typeName,
            string implementationName,
            // Due to a bug in Asp.Net Core 2.1 need to have the [FromQuery] attribute along with the name specified
            // https://github.com/aspnet/Mvc/issues/8126  Should be fixed in 2.2
            [FromQuery(Name = "dependencies")] string[] dependencies,
            bool?hasContinuousDelivery,
            DateTime?asOf,
            string topic,
            string team
            )
        {
            var parsedDependencies = new List <(string Name, string Version, RangeSpecifier RangeSpecifier)>();

            if (dependencies.Any())
            {
                foreach (var dependency in dependencies)
                {
                    var dependencyParts = dependency.Split(':');

                    var    dependencyName    = dependencyParts[0];
                    string dependencyVersion = null;

                    if (dependencyParts.Length == 2)
                    {
                        dependencyVersion = dependencyParts[1];
                    }

                    if (string.IsNullOrWhiteSpace(dependencyVersion))
                    {
                        parsedDependencies.Add((dependencyParts[0], null, RangeSpecifier.Unspecified));
                    }
                    else
                    {
                        var rangeSpecifier = RangeSpecifier.Unspecified;

                        var match = Regex.Match(dependencyVersion, rangeSpecifierRegex);

                        if (match.Success)
                        {
                            switch (match.Value)
                            {
                            case ">=":
                                dependencyVersion = dependencyVersion.Replace(">=", "");
                                rangeSpecifier    = RangeSpecifier.GreaterThanOrEqualTo;
                                break;

                            case ">":
                                dependencyVersion = dependencyVersion.Replace(">", "");
                                rangeSpecifier    = RangeSpecifier.GreaterThan;
                                break;

                            case "<":
                                dependencyVersion = dependencyVersion.Replace("<", "");
                                rangeSpecifier    = RangeSpecifier.LessThan;
                                break;

                            case "<=":
                                dependencyVersion = dependencyVersion.Replace("<=", "");
                                rangeSpecifier    = RangeSpecifier.LessThanOrEqualTo;
                                break;
                            }
                        }

                        parsedDependencies.Add((dependencyName, dependencyVersion, rangeSpecifier));
                    }
                }
            }

            var repositorySearch = new RepositorySearch
            {
                TypeName              = typeName,
                ImplementationName    = implementationName,
                HasContinuousDelivery = hasContinuousDelivery,
                Dependencies          = parsedDependencies,
                AsOf  = asOf,
                Team  = team,
                Topic = topic
            };

            var repositoryNames = await repositoryManager.SearchAsync(repositorySearch);

            return(repositoryNames);
        }
Example #22
0
        public IList <IDictionary <string, object> > RepositorySearch(IDictionary <string, string> properties,
                                                                      IList <DateRange> dateRanges = null,
                                                                      ObjectStore objectStore      = P8ContentEngine.DefaultObjectStore,
                                                                      DocumentClass documentClass  = P8ContentEngine.DefaultDocumentClass,
                                                                      bool adminOverride           = false)
        {
            var whereClause = string.Concat(properties.Aggregate
                                            (
                                                string.Empty, (current, pt) =>
            {
                string strRet = "";
                if (pt.Key == "WorkflowGUID")
                {
                    strRet += string.Concat
                              (
                        current, string.Format
                        (
                            " AND dc1.[{0}] = '{1}'",
                            pt.Key,
                            pt.Value.Replace("'", "''")
                        )
                              );
                }
                else
                {
                    strRet += string.Concat
                              (
                        current, string.Format
                        (
                            " AND dc1.[{0}] LIKE '%{1}%'",
                            pt.Key,
                            pt.Value.Replace("'", "''")
                        )
                              );
                }
                return(strRet);
            }
                                            ), BuildDateRangeSQL(dateRanges));

            var repositorySearch = new RepositorySearch
            {
                SearchScope = new ObjectStoreScope
                {
                    objectStore = objectStore.GetDescription()
                },
                SearchSQL = string.Format(
                    @"SELECT TOP 500 * FROM {0} dc1 WHERE {1}",
                    documentClass.GetDescription(),
                    Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase))
            };

//			var repositorySearch = new RepositorySearch
//			{
//				SearchScope = new ObjectStoreScope
//				{
//					objectStore = objectStore.GetDescription()
//				},
//				SearchSQL = string.Format(
//					@"SELECT TOP 500 dc1.*
//						FROM {0} dc1 RIGHT OUTER JOIN {0} dc2 ON dc1.ID = dc2.ID
//						WHERE ({1})
//						OR (dc1.ID = dc2.RelatedDocumentID OR dc1.RelatedDocumentID = dc2.RelatedDocumentID)
//						OPTIONS (FULLTEXTROWLIMIT 500)",
//					documentClass.GetDescription(),
//					Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase))
//			};

            var searchResult = Search(repositorySearch, adminOverride);

            var repositoryResults = new List <IDictionary <string, object> >();

            if (searchResult != null && searchResult.Object != null)
            {
                repositoryResults.AddRange
                (
                    searchResult.Object.Select
                    (
                        o => o.Property.ToDictionary <PropertyType, string, object>
                        (
                            p => p.propertyId, Utilities.GetPropertyValue
                        )
                    )
                );
            }

            return(repositoryResults);
        }
 public async Task <List <string> > SearchAsync(RepositorySearch repositorySearch)
 {
     throw new NotImplementedException();
     //return await repositorySearchRepository.SearchAsync(repositorySearch).ConfigureAwait(false);
 }
        public async Task <List <CountAggregationResult> > SearchAsync(RepositorySearch repositorySearch)
        {
            var countAggregations = await repositoryImplementationsRepository.SearchAsync(repositorySearch).ConfigureAwait(false);

            return(countAggregations);
        }
Example #25
0
        public List <Repository> Search(RepositorySearch repositorySearch)
        {
            SearchResults repositorys = _giteaApi.SearchRepository(repositorySearch.OnlyAdmin, repositorySearch.KeyWord, repositorySearch.Page).Result;

            return(repositorys.Data);
        }
        public async Task <List <RepositoryDependencySearchResult> > ReadAsync(string name, RepositorySearch repositorySearch)
        {
            var dbConnection = repositoryAnalysisContext.Database.GetDbConnection();

            var respositoryDependencySearchResults = await dbConnection.QueryAsync <Model.EntityFramework.RepositoryDependency, RepositoryDependencySearchResult, RepositoryDependencySearchResult>(
                @"SELECT name, version, Count(*) count
                FROM repository_dependency  RD
                JOIN repository_snapshot RS 
	                on RS.repository_snapshot_id = RD.repository_snapshot_id
	                and RS.window_ends_on is null
                WHERE name = @name
                GROUP BY name, version, padded_version
                order by padded_version",
                (repositoryDepenency, repositoryDependencySearchResult) =>
            {
                repositoryDependencySearchResult.RepositoryDependency = mapper.Map <ServiceModel.RepositoryDependency>(repositoryDepenency);

                return(repositoryDependencySearchResult);
            },
                new { name = name },
                splitOn : "count");

            if (respositoryDependencySearchResults != null && respositoryDependencySearchResults.Any())
            {
                return(respositoryDependencySearchResults.ToList());
            }
            else
            {
                return(new List <RepositoryDependencySearchResult>());
            }
        }
Example #27
0
 public ActionResult Index(RepositorySearch repositorySearch)
 {
     return(View());
 }
Example #28
0
        public async Task <ActionResult <List <string> > > GetAsync(
            string typeName,
            string implementationName,
            // Due to a bug in Asp.Net Core 2.1 need to have the [FromQuery] attribute along with the name specified
            // https://github.com/aspnet/Mvc/issues/8126  Should be fixed in 2.2
            [FromQuery(Name = "dependencies")] string[] dependencies,
            bool?hasContinuousDelivery,
            DateTime?asOf,
            string topic,
            string team,
            string teamPermissions
            )
        {
            var parsedDependencies = new List <(string Name, string Version, RangeSpecifier RangeSpecifier)>();

            if (dependencies.Any())
            {
                foreach (var dependency in dependencies)
                {
                    var depenencyAndVersionMatch = Regex.Match(dependency, dependencyAndVersionRegex);

                    if (!depenencyAndVersionMatch.Success)
                    {
                        parsedDependencies.Add((dependency, null, RangeSpecifier.Unspecified));
                    }
                    else
                    {
                        var rangeSpecifier = RangeSpecifier.Unspecified;

                        // Match the range specifier to an enum value
                        switch (depenencyAndVersionMatch.Groups["RangeSpecifier"].Value)
                        {
                        case ">=":
                            rangeSpecifier = RangeSpecifier.GreaterThanOrEqualTo;
                            break;

                        case ">":
                            rangeSpecifier = RangeSpecifier.GreaterThan;
                            break;

                        case "<":
                            rangeSpecifier = RangeSpecifier.LessThan;
                            break;

                        case "<=":
                            rangeSpecifier = RangeSpecifier.LessThanOrEqualTo;
                            break;

                        case "=":
                            rangeSpecifier = RangeSpecifier.EqualTo;
                            break;
                        }

                        var dependencyName    = depenencyAndVersionMatch.Groups["DependencyName"].Value;
                        var dependencyVersion = depenencyAndVersionMatch.Groups["VersionNumber"].Value;

                        parsedDependencies.Add((dependencyName, dependencyVersion, rangeSpecifier));
                    }
                }
            }

            var repositorySearch = new RepositorySearch
            {
                TypeName              = typeName,
                ImplementationName    = implementationName,
                HasContinuousDelivery = hasContinuousDelivery,
                Dependencies          = parsedDependencies,
                AsOf            = asOf,
                Team            = team,
                Topic           = topic,
                TeamPermissions = teamPermissions
            };

            var repositoryNames = await repositoryManager.SearchAsync(repositorySearch);

            return(repositoryNames);
        }