本文整理汇总了Golang中github.com/pomack/dsocial/go/models/dsocial.Group.IsSimilarOrUpdated方法的典型用法代码示例。如果您正苦于以下问题:Golang Group.IsSimilarOrUpdated方法的具体用法?Golang Group.IsSimilarOrUpdated怎么用?Golang Group.IsSimilarOrUpdated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pomack/dsocial/go/models/dsocial.Group
的用法示例。
在下文中一共展示了Group.IsSimilarOrUpdated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findMatchingDsocialGroup
func (p *Pipeline) findMatchingDsocialGroup(ds DataStoreService, dsocialUserId string, group *Group) (extDsocialGroup *dm.Group, isSame bool, err os.Error) {
emptyGroup := new(dm.Group)
if group.DsocialGroupId != "" {
extDsocialGroup, _, _ = ds.RetrieveDsocialGroup(dsocialUserId, group.DsocialGroupId)
if extDsocialGroup != nil {
_, isSame = emptyGroup.IsSimilarOrUpdated(extDsocialGroup, group.Value)
fmt.Printf("[PIPELINE]: findMatchingDsocialGroup for %s with based on existing group id will use %s and isSame %v\n", group.Value.Name, extDsocialGroup.Name, isSame)
}
}
if extDsocialGroup == nil {
// this is a new group from an existing service
potentialMatches, err := ds.SearchForDsocialGroups(dsocialUserId, group.Value.Name)
if err != nil {
return nil, false, err
}
for _, potentialMatch := range potentialMatches {
var isSimilar bool
if isSimilar, isSame = emptyGroup.IsSimilarOrUpdated(potentialMatch, group.Value); isSimilar {
extDsocialGroup = potentialMatch
break
}
}
if extDsocialGroup != nil {
fmt.Printf("[PIPELINE]: findMatchingDsocialGroup for %s was %s and isSame %v\n\tStoring mapping: %s/%s/%s -> %s\n", group.Value.Name, extDsocialGroup.Name, isSame, group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, extDsocialGroup.Id)
_, _, err = ds.StoreDsocialExternalGroupMapping(group.ExternalServiceId, group.ExternalUserId, group.ExternalGroupId, dsocialUserId, extDsocialGroup.Id)
group.DsocialGroupId = extDsocialGroup.Id
} else {
fmt.Printf("[PIPELINE]: findMatchingDsocialGroup cannot find similar for %s\n", group.Value.Name)
}
}
return extDsocialGroup, isSame, err
}
示例2: 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
}