當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。