当前位置: 首页>>代码示例>>Golang>>正文


Golang Group.GenerateChanges方法代码示例

本文整理汇总了Golang中github.com/pomack/dsocial/go/models/dsocial.Group.GenerateChanges方法的典型用法代码示例。如果您正苦于以下问题:Golang Group.GenerateChanges方法的具体用法?Golang Group.GenerateChanges怎么用?Golang Group.GenerateChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pomack/dsocial/go/models/dsocial.Group的用法示例。


在下文中一共展示了Group.GenerateChanges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: groupImport


//.........这里部分代码省略.........
				fmt.Printf("[PIPELINE]: groupImport() before store dsoc group ExternalGroupId: %v and extDsocialGroup.Id %v matchingGroup.Id %v\n", group.ExternalGroupId, extDsocialGroup.Id, matchingGroup.Id)
				//group.ExternalGroupId = extDsocialGroup.Id
				//extDsocialGroup.Id = group.DsocialGroupId
				extDsocialGroup, err = ds.StoreDsocialGroupForExternalGroup(group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, dsocialUserId, extDsocialGroup)
				if extDsocialGroup == nil || err != nil {
					return matchingGroup, "", err
				}
				//extDsocialGroup.Id = group.DsocialGroupId
				fmt.Printf("[PIPELINE]: groupImport() before store mapping ExternalGroupId: %v and DsocialGroupId %v\n", group.ExternalGroupId, group.DsocialGroupId)
				if _, _, err = ds.StoreDsocialExternalGroupMapping(group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, dsocialUserId, group.DsocialGroupId); err != nil {
					return matchingGroup, "", err
				}
			}
		}
	} else {
		// we have a mapping for this external group to an internal group mapping
		// from THIS service, therefore let's use it
		if group.DsocialGroupId == "" {
			group.DsocialGroupId, err = ds.DsocialIdForExternalGroupId(group.ExternalServiceId, group.ExternalUserId, dsocialUserId, group.ExternalGroupId)
			if err != nil {
				return nil, "", err
			}
		}
		if group.DsocialGroupId != "" {
			matchingGroup, _, err = ds.RetrieveDsocialGroup(dsocialUserId, group.DsocialGroupId)
			if err != nil {
				return nil, "", err
			}
		}
	}
	// ensure we have a contact Id
	if group.DsocialGroupId == "" {
		if matchingGroup != nil {
			group.DsocialGroupId = matchingGroup.Id
			fmt.Printf("[PIPELINE]: Will be using matchingGroup Id: %v\n", matchingGroup.Id)
		}
		if group.DsocialGroupId == "" {
			newGroup := &dm.Group{UserId: dsocialUserId}
			AddIdsForDsocialGroup(newGroup, ds, dsocialUserId)
			thegroup, err := ds.StoreDsocialGroup(dsocialUserId, newGroup.Id, newGroup)
			if err != nil {
				return nil, "", err
			}
			group.DsocialGroupId = thegroup.Id
		}
	}
	if _, isSame = emptyGroup.IsSimilarOrUpdated(extDsocialGroup, group.Value); isSame {
		return matchingGroup, "", nil
	}
	l := new(list.List)
	emptyGroup.GenerateChanges(extDsocialGroup, group.Value, nil, l)
	l = p.removeUnacceptedChanges(l, allowAdd, allowDelete, allowUpdate)
	changes := make([]*dm.Change, l.Len())
	for i, iter := 0, l.Front(); iter != nil; i, iter = i+1, iter.Next() {
		changes[i] = iter.Value.(*dm.Change)
	}
	changeset := &dm.ChangeSet{
		CreatedAt:      time.UTC().Format(dm.UTC_DATETIME_FORMAT),
		ChangedBy:      group.ExternalServiceId,
		ChangeImportId: group.ExternalGroupId,
		RecordId:       group.DsocialGroupId,
		Changes:        changes,
	}
	_, err = ds.StoreGroupChangeSet(dsocialUserId, changeset)
	if err != nil {
		return matchingGroup, changeset.Id, nil
	}
	if extDsocialGroup == nil {
		fmt.Printf("[PIPELINE]: OriginalExternalGroup is nil and group.DsocialGroupId is %v and group.Value.Id was %v\n", group.DsocialGroupId, group.Value.Id)
		group.Value.Id = group.DsocialGroupId
		AddIdsForDsocialGroup(group.Value, ds, dsocialUserId)
		group.Value, err = ds.StoreDsocialGroup(dsocialUserId, group.DsocialGroupId, group.Value)
		if err != nil {
			return matchingGroup, changeset.Id, err
		}
		storedDsocialGroup, err := ds.StoreDsocialGroupForExternalGroup(group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, dsocialUserId, group.Value)
		_, _, err2 := ds.StoreDsocialExternalGroupMapping(group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, dsocialUserId, group.DsocialGroupId)
		if err == nil {
			err = err2
		}
		return storedDsocialGroup, changeset.Id, err
	}
	var storedDsocialGroup *dm.Group = nil
	if group.DsocialGroupId != "" {
		if storedDsocialGroup, _, err = ds.RetrieveDsocialGroup(dsocialUserId, group.DsocialGroupId); err != nil {
			return matchingGroup, changeset.Id, err
		}
	}
	if storedDsocialGroup == nil {
		storedDsocialGroup = new(dm.Group)
	}
	for j, iter := 0, l.Front(); iter != nil; j, iter = j+1, iter.Next() {
		change := iter.Value.(*dm.Change)
		dm.ApplyChange(storedDsocialGroup, change)
		changes[j] = change
	}
	AddIdsForDsocialGroup(storedDsocialGroup, ds, dsocialUserId)
	_, err = ds.StoreDsocialGroup(dsocialUserId, group.DsocialGroupId, storedDsocialGroup)
	return storedDsocialGroup, changeset.Id, err
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:101,代码来源:pipeline.go


注:本文中的github.com/pomack/dsocial/go/models/dsocial.Group.GenerateChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。