コード例 #1
0
        private async Task <IEnumerable <String> > ImportUserAsync(APIOptions apiOptions, IGenericRepository <kCura.Relativity.Client.DTOs.User> userRepository)
        {
            List <String> violations = new List <string>();

            kCura.Relativity.Client.DTOs.User user = null;
            try
            {
                apiOptions.WorkspaceID = -1;
                user = new kCura.Relativity.Client.DTOs.User()
                {
                    FirstName                     = (String)await FirstName.GetDataValueAsync(),
                    LastName                      = (String)await LastName.GetDataValueAsync(),
                    EmailAddress                  = (String)await EmailAddress.GetDataValueAsync(),
                    Groups                        = _groupList,
                    Type                          = _userType,
                    Client                        = _client,
                    RelativityAccess              = ((Boolean?)await RelativityAccess.GetDataValueAsync()).GetValueOrDefault(),
                    DocumentSkip                  = _documentSkip,
                    BetaUser                      = ((Boolean?)await BetaUser.GetDataValueAsync()).GetValueOrDefault(),
                    ChangeSettings                = ((Boolean?)await ChangeSettings.GetDataValueAsync()).GetValueOrDefault(),
                    KeyboardShortcuts             = ((Boolean?)await KeyboardShortcuts.GetDataValueAsync()).GetValueOrDefault(),
                    ItemListPageLength            = ((Int32?)await ItemListPageLength.GetDataValueAsync()).GetValueOrDefault(),
                    DefaultSelectedFileType       = _defaultSelectedFileType,
                    SkipDefaultPreference         = _skipDefaultPreference,
                    EnforceViewerCompatibility    = ((Boolean?)await EnforceViewerCompatibility.GetDataValueAsync()).GetValueOrDefault(),
                    AdvancedSearchPublicByDefault = ((Boolean?)await AdvancedSearchPublicByDefault.GetDataValueAsync()).GetValueOrDefault(),
                    NativeViewerCacheAhead        = ((Boolean?)await NativeViewerCacheAhead.GetDataValueAsync()).GetValueOrDefault(),
                    CanChangeDocumentViewer       = ((Boolean?)await ChangeDocumentViewer.GetDataValueAsync()).GetValueOrDefault(),
                    DocumentViewer                = _documentViewer,
                    TrustedIPs                    = String.Empty,
                    ChangePassword                = ((Boolean?)await CanChangePassword.GetDataValueAsync()).GetValueOrDefault(),
                    MaximumPasswordAge            = ((Int32?)await MaximumPasswordAgeInDays.GetDataValueAsync()).GetValueOrDefault(),
                    DataFocus                     = 1, // This field is no longer utilized in Relativity, however it's hardcoded because it is required
                    ChangePasswordNextLogin       = ((Boolean?)await UserMustChangePasswordOnNextLogin.GetDataValueAsync()).GetValueOrDefault()
                };

                ArtifactId = userRepository.CreateSingle(user);
            }
            catch (Exception ex)
            {
                String msg = null;
                if (ex.ToString().Contains("The entered E-Mail Address is already associated with a user") && user != null && !String.IsNullOrWhiteSpace(user.EmailAddress))
                {
                    msg = String.Format(Constant.ErrorMessages.UserAlreadyExists, user.EmailAddress);
                }
                else
                {
                    msg = ex.ToString();
                }
                violations.Add(msg);
            }
            return(violations);
        }
コード例 #2
0
        public override async Task <IEnumerable <String> > ImportAsync(APIOptions apiOptions, IRsapiRepositoryGroup repositoryGroup, IArtifactQueries artifactQueryHelper, IHelper helper, IDBContext eddsDbContext, ISqlQueryHelper sqlQueryHelper)
        {
            var violations = new List <string>();

            try
            {
                // Skip import if user already exists
                if (await UserExistsInRelativity(apiOptions, repositoryGroup.UserRepository, artifactQueryHelper, (String)(await EmailAddress.GetDataValueAsync() ?? "")))
                {
                    var msg = String.Format(Constant.ErrorMessages.UserAlreadyExists, (String)await EmailAddress.GetDataValueAsync());
                    violations.Add(msg);
                }
                else
                {
                    // Make sure user is validated
                    if (Validated == false)
                    {
                        violations.AddRange(await ValidateAsync(apiOptions, repositoryGroup, artifactQueryHelper, eddsDbContext, sqlQueryHelper));
                    }

                    // Import user object
                    if (!violations.Any())
                    {
                        violations.AddRange(await ImportUserAsync(apiOptions, repositoryGroup.UserRepository));
                    }

                    // Save the User's keywords and notes
                    if (!violations.Any())
                    {
                        violations.AddRange(await SaveUserKeywordAndNotesAsync(sqlQueryHelper, eddsDbContext));
                    }

                    // Import the Login Method Object
                    if (!violations.Any())
                    {
                        violations.AddRange(await ImportLoginMethodAsync(helper));
                    }

                    if (violations.Any())
                    {
                        // Check to see if user was partially imported
                        if (await UserExistsInRelativity(apiOptions, repositoryGroup.UserRepository, artifactQueryHelper, (String)(await EmailAddress.GetDataValueAsync() ?? "")))
                        {
                            // Only prepend msg and present to user if the user didn't already exists
                            var userAlreadyExistsMsg = String.Format(Constant.ErrorMessages.UserAlreadyExists, (String)await EmailAddress.GetDataValueAsync());
                            if (!violations.Any(x => x.Contains(userAlreadyExistsMsg)))
                            {
                                violations = violations.Select(x => Constant.ErrorMessages.UserPartiallyImportedPrepend + x).ToList();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                violations.Add(ex.ToString());
            }

            return(violations);
        }