internal AuthorityTokenSummary GetAuthorityTokenSummary(AuthorityToken authorityToken) { return(new AuthorityTokenSummary( authorityToken.Name, authorityToken.Description )); }
/// <summary> /// Import authority groups. /// </summary> /// <remarks> /// Creates any authority groups that do not already exist. /// This method performs an additive import. It will never remove an existing authority group or /// remove authority tokens from an existing group. /// </remarks> /// <param name="groupDefs"></param> /// <param name="context"></param> public IList <AuthorityGroup> Import(IEnumerable <AuthorityGroupDefinition> groupDefs, IUpdateContext context) { // first load all the existing tokens into memory // there should not be that many tokens ( < 500), so this should not be a problem IAuthorityTokenBroker tokenBroker = context.GetBroker <IAuthorityTokenBroker>(); IList <AuthorityToken> existingTokens = tokenBroker.FindAll(); // load existing groups IAuthorityGroupBroker groupBroker = context.GetBroker <IAuthorityGroupBroker>(); IList <AuthorityGroup> existingGroups = groupBroker.FindAll(); foreach (AuthorityGroupDefinition groupDef in groupDefs) { AuthorityGroup group = CollectionUtils.SelectFirst(existingGroups, g => g.Name == groupDef.Name); // if group does not exist, create it if (group == null) { group = new AuthorityGroup { Name = groupDef.Name, Description = groupDef.Description, DataGroup = groupDef.DataGroup }; context.Lock(group, DirtyState.New); existingGroups.Add(group); } // process all token nodes contained in group foreach (string tokenName in groupDef.Tokens) { AuthorityToken token = CollectionUtils.SelectFirst(existingTokens, t => t.Name == tokenName); // ignore non-existent tokens if (token == null) { continue; } // add the token to the group group.AuthorityTokens.Add(token); } } return(existingGroups); }
protected override void Import(AuthorityGroupData data, IUpdateContext context) { AuthorityGroup group = LoadOrCreateGroup(data.Name, context); group.Description = data.Description; group.DataGroup = data.DataGroup; if (data.Tokens != null) { foreach (string token in data.Tokens) { AuthorityTokenSearchCriteria where = new AuthorityTokenSearchCriteria(); where.Name.EqualTo(token); AuthorityToken authToken = CollectionUtils.FirstElement(context.GetBroker <IAuthorityTokenBroker>().Find(where)); if (authToken != null) { group.AuthorityTokens.Add(authToken); } } } }
private static AuthorityToken ProcessToken(AuthorityTokenDefinition tokenDef, ICollection <AuthorityToken> existingTokens, IUpdateContext context) { // look for an existing instance of the token, or a token that should be renamed to this token var token = existingTokens.FirstOrDefault(t => t.Name == tokenDef.Token || tokenDef.FormerIdentities.Contains(t.Name)); if (token != null) { // update the name (in the case it is a rename) token.Name = tokenDef.Token; // update the description token.Description = tokenDef.Description; } else { // the token does not already exist, so create it token = new AuthorityToken(tokenDef.Token, tokenDef.Description); context.Lock(token, DirtyState.New); existingTokens.Add(token); } return(token); }
private static AuthorityToken ProcessToken(AuthorityTokenDefinition tokenDef, ICollection<AuthorityToken> existingTokens, IUpdateContext context) { // look for an existing instance of the token, or a token that should be renamed to this token var token = existingTokens.FirstOrDefault(t => t.Name == tokenDef.Token || tokenDef.FormerIdentities.Contains(t.Name)); if (token != null) { // update the name (in the case it is a rename) token.Name = tokenDef.Token; // update the description token.Description = tokenDef.Description; } else { // the token does not already exist, so create it token = new AuthorityToken(tokenDef.Token, tokenDef.Description); context.Lock(token, DirtyState.New); existingTokens.Add(token); } return token; }