Beispiel #1
0
        private static ProfileColumn CreateSystemPropertyColumn(
            PropertyTypeInfo propertyTypeInfo, ProfileColumns profileColumns = null)
        {
            var systemPredefineds = new HashSet <PropertyTypePredefined>
            {
                PropertyTypePredefined.ID,
                PropertyTypePredefined.Name,
                PropertyTypePredefined.Description,
                PropertyTypePredefined.CreatedBy,
                PropertyTypePredefined.CreatedOn,
                PropertyTypePredefined.LastEditedBy,
                PropertyTypePredefined.LastEditedOn,
                PropertyTypePredefined.ArtifactType
            };

            if (!propertyTypeInfo.PredefinedMatches(systemPredefineds) ||
                profileColumns != null && profileColumns.PredefinedMatches(propertyTypeInfo.Predefined))
            {
                return(null);
            }

            return(new ProfileColumn(
                       propertyTypeInfo.Name,
                       propertyTypeInfo.Predefined,
                       propertyTypeInfo.PrimitiveType));
        }
Beispiel #2
0
        public async Task GetColumnsAsync_ProfileColumnsSettingHasSamePredefeinedAsPropertyTypeInfoUnSelectedColumnsEmpty_Success()
        {
            _profileColumnsSettings = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("System", PropertyTypePredefined.ID, PropertyPrimitiveType.Number, 2)
            });

            _propertyTypeInfos = new List <PropertyTypeInfo>
            {
                new PropertyTypeInfo
                {
                    Id            = 2,
                    Predefined    = PropertyTypePredefined.ID,
                    Name          = "System",
                    PrimitiveType = PropertyPrimitiveType.Number
                }
            };

            InitializeProfileColumnsAndPropertyTypeInfos(_profileColumnsSettings, _propertyTypeInfos);

            var result = await _collectionService.GetColumnsAsync(_collectionId, _userId);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.UnselectedColumns.Any());
        }
Beispiel #3
0
        public async Task <bool> SaveProfileColumnsAsync(int collectionId, ProfileColumns profileColumns, int userId)
        {
            if (userId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            var collection = await GetCollectionAsync(collectionId, userId);

            var artifacts = await GetArtifactItemsDetailsAsync(collectionId, userId);

            var propertyTypeInfos = await GetPropertyTypeInfosAsync(artifacts);

            var propertyTypes  = GetUnselectedColumns(propertyTypeInfos);
            var invalidColumns = profileColumns.GetInvalidColumns(propertyTypes);

            if (invalidColumns.Any())
            {
                throw ArtifactListExceptionHelper.InvalidColumnsException(invalidColumns);
            }

            var savingProfileColumnsTuple = profileColumns.ToValidColumns(propertyTypeInfos);

            await _artifactListService.SaveProfileColumnsAsync(collection.Id,
                                                               savingProfileColumnsTuple.Item1, userId);

            return(savingProfileColumnsTuple.Item2);
        }
Beispiel #4
0
        public async Task SaveProfileColumnsAsync_AllDataValid_SuccessResult()
        {
            var propertyTypeInfos = new List <PropertyTypeInfo>();

            _profileColumns = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("System", PropertyTypePredefined.ArtifactType, PropertyPrimitiveType.Text),
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2)
            });

            foreach (var column in _profileColumns.Items)
            {
                propertyTypeInfos.Add(new PropertyTypeInfo()
                {
                    Id            = column.PropertyTypeId,
                    Name          = column.PropertyName,
                    Predefined    = column.Predefined,
                    PrimitiveType = column.PrimitiveType
                });
            }

            _collectionsRepository
            .Setup(q => q.GetPropertyTypeInfosForItemTypesAsync(
                       It.IsAny <IEnumerable <int> >(), null))
            .ReturnsAsync(propertyTypeInfos);

            await _collectionService.SaveProfileColumnsAsync(_collectionId, _profileColumns, _userId);
        }
Beispiel #5
0
        public async Task SaveProfileColumnsAsync_InvalidColumnsForSaving_InvalidName_ThrowInvalidColumnsException()
        {
            var propertyTypeInfos = new List <PropertyTypeInfo>();

            _profileColumns = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("System", PropertyTypePredefined.ArtifactType, PropertyPrimitiveType.Text, 1),
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2)
            });

            foreach (var column in _profileColumns.Items)
            {
                propertyTypeInfos.Add(new PropertyTypeInfo()
                {
                    Id            = column.PropertyTypeId,
                    Name          = column.PropertyName + DateTime.Now.ToLongDateString(),
                    Predefined    = column.Predefined,
                    PrimitiveType = column.PrimitiveType
                });
            }

            _collectionsRepository
            .Setup(q => q.GetPropertyTypeInfosForItemTypesAsync(
                       It.IsAny <IEnumerable <int> >(), null))
            .ReturnsAsync(propertyTypeInfos);

            await _collectionService.SaveProfileColumnsAsync(_collectionId, _profileColumns, _userId);
        }
Beispiel #6
0
 private static IEnumerable <ProfileColumn> GetSelectedColumns(
     IReadOnlyList <PropertyTypeInfo> propertyTypeInfos, ProfileColumns profileColumns, string search)
 {
     return(profileColumns.Items
            .Where(column => column.ExistsIn(propertyTypeInfos) && column.NameMatches(search))
            .Select(column => new ProfileColumn(
                        column.PropertyName, column.Predefined, column.PrimitiveType, column.PropertyTypeId)));
 }
Beispiel #7
0
        public async Task <ProfileColumns> GetProfileColumnsAsync(
            int itemId, int userId, ProfileColumns defaultColumns = null)
        {
            var existingSettings = await _artifactListSettingsRepository.GetSettingsAsync(itemId, userId);

            return(existingSettings == null || existingSettings.Columns.IsEmpty()
                ? defaultColumns
                : ArtifactListHelper.ConvertXmlProfileSettingsToProfileColumns(existingSettings));
        }
Beispiel #8
0
 private static IEnumerable <ProfileColumn> GetUnselectedColumns(
     IEnumerable <PropertyTypeInfo> propertyTypeInfos, ProfileColumns profileColumns = null, int?count = null)
 {
     return(propertyTypeInfos
            .Select(info => info.IsCustom ?
                    CreateCustomPropertyColumn(info, profileColumns) :
                    CreateSystemPropertyColumn(info, profileColumns))
            .Where(column => column != null).TakeIfNotNull(count)
            .ToList());
 }
Beispiel #9
0
        private void InitializeProfileColumnsAndPropertyTypeInfos(ProfileColumns profileColumnsSettings, IReadOnlyList <PropertyTypeInfo> propertyTypeInfos)
        {
            _artifactListService
            .Setup(s => s.GetProfileColumnsAsync(It.IsAny <int>(), It.IsAny <int>(), ProfileColumns.Default))
            .ReturnsAsync(profileColumnsSettings);

            _collectionsRepository
            .Setup(r => r.GetPropertyTypeInfosForItemTypesAsync(It.IsAny <IEnumerable <int> >(), It.IsAny <string>()))
            .ReturnsAsync((propertyTypeInfos));
        }
Beispiel #10
0
        public async Task GetColumnsAsync_ProfileColumnsSettingsAreEmptyUnSelectedColumnsNotEmpty_Success()
        {
            _profileColumnsSettings = new ProfileColumns(new List <ProfileColumn>());

            InitializeProfileColumnsAndPropertyTypeInfos(_profileColumnsSettings, _propertyTypeInfos);

            var result = await _collectionService.GetColumnsAsync(_collectionId, _userId);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.UnselectedColumns.Any());
        }
Beispiel #11
0
        private static ProfileColumn CreateCustomPropertyColumn(
            PropertyTypeInfo propertyTypeInfo, ProfileColumns profileColumns = null)
        {
            if (profileColumns != null && profileColumns.PropertyTypeIdMatches(propertyTypeInfo.Id.Value))
            {
                return(null);
            }

            return(new ProfileColumn(
                       propertyTypeInfo.Name,
                       propertyTypeInfo.Predefined,
                       propertyTypeInfo.PrimitiveType,
                       propertyTypeInfo.Id));
        }
Beispiel #12
0
        public async Task <HttpResponseMessage> SaveColumnsSettingsAsync(
            int id, [FromBody] ProfileColumnsDto profileColumnsDto)
        {
            if (profileColumnsDto == null || profileColumnsDto.Items.IsEmpty())
            {
                throw new BadRequestException(
                          ErrorMessages.Collections.ColumnsSettingsModelIsIncorrect, ErrorCodes.BadRequest);
            }

            var profileColumns          = new ProfileColumns(profileColumnsDto.Items);
            var customPropertiesChanged = await _collectionsService.SaveProfileColumnsAsync(id, profileColumns, Session.UserId);

            return(customPropertiesChanged
                ? Request.CreateResponse(HttpStatusCode.OK, ErrorMessages.ArtifactList.ColumnsSettings.ChangedCustomProperties)
                : Request.CreateResponse(HttpStatusCode.NoContent));
        }
 public static List <XmlProfileColumn> ConvertProfileColumnsToXmlProfileSettings(ProfileColumns profileColumns) =>
 profileColumns.Items?
 .Select(column => new XmlProfileColumn
 {
     PropertyName   = column.PropertyName,
     PropertyTypeId = column.PropertyTypeId,
     Predefined     = (int)column.Predefined,
     PrimitiveType  = (int)column.PrimitiveType
 })
 .ToList();
Beispiel #14
0
 public async Task <int> SaveProfileColumnsAsync(int itemId, ProfileColumns profileColumns, int userId)
 {
     return(await SaveSettingsAsync(itemId, userId, new ProfileSettingsParams { Columns = profileColumns }));
 }
Beispiel #15
0
        public void Initialize()
        {
            _sqlHelperMock                 = new SqlHelperMock();
            _collectionsRepository         = new Mock <ICollectionsRepository>();
            _artifactRepository            = new Mock <IArtifactRepository>();
            _lockArtifactsRepository       = new Mock <ILockArtifactsRepository>();
            _itemInfoRepository            = new Mock <IItemInfoRepository>();
            _artifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>();
            _searchEngineService           = new Mock <ISearchEngineService>();
            _artifactListService           = new Mock <IArtifactListService>();
            _collectionService             = new CollectionsService(
                _collectionsRepository.Object,
                _artifactRepository.Object,
                _lockArtifactsRepository.Object,
                _itemInfoRepository.Object,
                _artifactPermissionsRepository.Object,
                _sqlHelperMock,
                _searchEngineService.Object,
                _artifactListService.Object);


            _artifactIds = new HashSet <int> {
                1, 2, 3
            };
            _collectionId          = 1;
            _searchArtifactsResult = new SearchArtifactsResult
            {
                ArtifactIds = _artifactIds,
                Total       = _artifactIds.Count
            };

            _profileColumnsSettings = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Number, 2)
            });

            _collectionPermissions = new Dictionary <int, RolePermissions>
            {
                { _collectionId, RolePermissions.Read | RolePermissions.Edit }
            };

            _collectionDetails = new ArtifactBasicDetails
            {
                ArtifactId   = _collectionId,
                ProjectId    = 1,
                DraftDeleted = false,
                PrimitiveItemTypePredefined = (int)ItemTypePredefined.ArtifactCollection,
                LockedByUserId = _userId
            };

            _artifacts = new List <ItemDetails>
            {
                new ItemDetails
                {
                    Name                        = "Artifact1",
                    ItemTypeId                  = 2,
                    VersionProjectId            = 1,
                    EndRevision                 = int.MaxValue,
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            };

            _artifactPermissions = new Dictionary <int, RolePermissions>();

            foreach (var itemDetails in _artifacts)
            {
                _artifactPermissions.Add(itemDetails.ItemTypeId, RolePermissions.Read);
            }

            _profileColumns = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2)
            });

            _propertyTypeInfos = new List <PropertyTypeInfo>
            {
                new PropertyTypeInfo
                {
                    Id            = 2,
                    Predefined    = PropertyTypePredefined.CustomGroup,
                    Name          = "Custom",
                    PrimitiveType = PropertyPrimitiveType.Number
                }
            };

            _artifactRepository
            .Setup(r => r.GetArtifactBasicDetails(_collectionId, _userId, null))
            .ReturnsAsync(_collectionDetails);

            _artifactPermissionsRepository
            .Setup(r => r.GetArtifactPermissions(_collectionId, _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(_collectionPermissions);

            _artifactPermissionsRepository
            .Setup(r => r.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(_artifactPermissions);

            _collectionsRepository
            .Setup(r => r.GetContentArtifactIdsAsync(_collectionId, _userId, It.IsAny <bool>()))
            .ReturnsAsync(_artifactIds.ToList());

            _collectionsRepository
            .Setup(r => r.RemoveArtifactsFromCollectionAsync(_collectionId, It.IsAny <IEnumerable <int> >(), _userId, null))
            .ReturnsAsync(_artifacts.Count);

            _itemInfoRepository
            .Setup(r => r.GetItemsDetails(It.IsAny <int>(), It.IsAny <List <int> >(), It.IsAny <bool>(), It.IsAny <int>(), null))
            .ReturnsAsync(_artifacts);

            _searchEngineService
            .Setup(s => s.Search(It.IsAny <int>(), It.IsAny <Pagination>(), It.IsAny <ScopeType>(), It.IsAny <bool>(), It.IsAny <int>(), null))
            .ReturnsAsync(_searchArtifactsResult);

            InitializeProfileColumnsAndPropertyTypeInfos(_profileColumnsSettings, _propertyTypeInfos);

            _reviewItemsRemovalParams =
                new ItemsRemovalParams
            {
                ItemIds = new List <int> {
                    1, 2, 3
                },
                SelectionType = SelectionType.Selected
            };
        }