func lookupIdentities(ctx context.Context, db *gorm.DB, remoteWorkItem RemoteWorkItem, providerType string, spaceID uuid.UUID) (*workitem.WorkItem, error) {
	identityRepository := account.NewIdentityRepository(db)
	//spaceSelfURL := rest.AbsoluteURL(goa.ContextRequest(ctx), app.SpaceHref(spaceID.String()))
	workItem := workitem.WorkItem{
		ID:      remoteWorkItem.ID,
		Type:    remoteWorkItem.Type,
		Fields:  make(map[string]interface{}),
		SpaceID: spaceID,
	}
	// copy all fields from remoteworkitem into result workitem
	for fieldName, fieldValue := range remoteWorkItem.Fields {
		// creator
		if fieldName == remoteCreatorLogin {
			if fieldValue == nil {
				workItem.Fields[workitem.SystemCreator] = nil
				continue
			}
			creatorLogin := fieldValue.(string)
			creatorProfileURL := remoteWorkItem.Fields[remoteCreatorProfileURL].(string)
			identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, providerType)
			if err != nil {
				return nil, errors.Wrap(err, "failed to create identity during lookup")
				return nil, err
			}
			// associate the identities to the work item
			workItem.Fields[workitem.SystemCreator] = identity.ID.String()
		} else if fieldName == remoteCreatorProfileURL {
			// ignore here, it is being processed above
		} else
		// assignees
		if fieldName == remoteAssigneeLogins {
			if fieldValue == nil {
				workItem.Fields[workitem.SystemAssignees] = make([]string, 0)
				continue
			}
			identities := make([]string, 0)
			assigneeLogins := fieldValue.([]string)
			assigneeProfileURLs := remoteWorkItem.Fields[remoteAssigneeProfileURLs].([]string)
			for i, assigneeLogin := range assigneeLogins {
				assigneeProfileURL := assigneeProfileURLs[i]
				identity, err := identityRepository.Lookup(context.Background(), assigneeLogin, assigneeProfileURL, providerType)
				if err != nil {
					return nil, err
				}
				identities = append(identities, identity.ID.String())
			}
			// associate the identities to the work item
			workItem.Fields[workitem.SystemAssignees] = identities
		} else if fieldName == remoteAssigneeProfileURLs {
			// ignore here, it is being processed above
		} else {
			// copy other fields
			workItem.Fields[fieldName] = fieldValue
		}
	}
	return &workItem, nil
}
// lookupIdentities looks up creator and assignee remote identities to local identities (already existing or to be created)
lookupIdentities looks up creator and assignee remote identities to local identities (already existing or to be created)
// lookupIdentities looks up creator and assignee remote identities to local identities ( already existing or to be created )
func lookupIdentities(ctx context.Context, db *gorm.DB, remoteWorkItem RemoteWorkItem, providerType string, spaceID uuid.UUID) (*workitem.WorkItem, error) {
	identityRepository := account.NewIdentityRepository(db)
	workItem := workitem.WorkItem{
		ID:      remoteWorkItem.ID,
		Type:    remoteWorkItem.Type,
		Fields:  make(map[string]interface{}),
		SpaceID: spaceID,
	}
	for fieldName, fieldValue := range remoteWorkItem.Fields {
		if fieldName == remoteCreatorLogin {
			if fieldValue == nil {
				workItem.Fields[workitem.SystemCreator] = nil
				continue
			}
			creatorLogin := fieldValue.(string)
			creatorProfileURL := remoteWorkItem.Fields[remoteCreatorProfileURL].(string)
			identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, providerType)
			if err != nil {
				return nil, errors.Wrap(err, "failed to create identity during lookup")
				return nil, err
			}
			workItem.Fields[workitem.SystemCreator] = identity.ID.String()
		} else if fieldName == remoteCreatorProfileURL {
		} else
		if fieldName == remoteAssigneeLogins {
			if fieldValue == nil {
				workItem.Fields[workitem.SystemAssignees] = make([]string, 0)
				continue
			}
			identities := make([]string, 0)
			assigneeLogins := fieldValue.([]string)
			assigneeProfileURLs := remoteWorkItem.Fields[remoteAssigneeProfileURLs].([]string)
			for i, assigneeLogin := range assigneeLogins {
				assigneeProfileURL := assigneeProfileURLs[i]
				identity, err := identityRepository.Lookup(context.Background(), assigneeLogin, assigneeProfileURL, providerType)
				if err != nil {
					return nil, err
				}
				identities = append(identities, identity.ID.String())
			}
			workItem.Fields[workitem.SystemAssignees] = identities
		} else if fieldName == remoteAssigneeProfileURLs {
		} else {
			workItem.Fields[fieldName] = fieldValue
		}
	}
	return &workItem, nil
}
func lookupIdentities ( ctx context . Context , db * gorm . DB , remoteWorkItem RemoteWorkItem , providerType string , spaceID uuid . UUID ) ( * workitem . WorkItem , error ) { identityRepository := account . NewIdentityRepository ( db ) workItem := workitem . WorkItem { ID : remoteWorkItem . ID , Type : remoteWorkItem . Type , Fields : make ( map [ string ] interface { } ) , SpaceID : spaceID , } for fieldName , fieldValue := range remoteWorkItem . Fields { if fieldName == remoteCreatorLogin { if fieldValue == nil { workItem . Fields [ workitem . SystemCreator ] = nil continue } creatorLogin := fieldValue . ( string ) creatorProfileURL := remoteWorkItem . Fields [ remoteCreatorProfileURL ] . ( string ) identity , err := identityRepository . Lookup ( context . Background ( ) , creatorLogin , creatorProfileURL , providerType ) if err != nil { return nil , errors . Wrap ( err , " " ) return nil , err } workItem . Fields [ workitem . SystemCreator ] = identity . ID . String ( ) } else if fieldName == remoteCreatorProfileURL { } else if fieldName == remoteAssigneeLogins { if fieldValue == nil { workItem . Fields [ workitem . SystemAssignees ] = make ( [ ] string , 0 ) continue } identities := make ( [ ] string , 0 ) assigneeLogins := fieldValue . ( [ ] string ) assigneeProfileURLs := remoteWorkItem . Fields [ remoteAssigneeProfileURLs ] . ( [ ] string ) for i , assigneeLogin := range assigneeLogins { assigneeProfileURL := assigneeProfileURLs [ i ] identity , err := identityRepository . Lookup ( context . Background ( ) , assigneeLogin , assigneeProfileURL , providerType ) if err != nil { return nil , err } identities = append ( identities , identity . ID . String ( ) ) } workItem . Fields [ workitem . SystemAssignees ] = identities } else if fieldName == remoteAssigneeProfileURLs { } else { workItem . Fields [ fieldName ] = fieldValue } } return & workItem , nil }
lookupIdentities looks up creator and assignee remote identities to local identities (already existing or to be created)
lookupIdentities looks up creator and assignee remote identities to local identities ( already existing or to be created )
//spaceSelfURL := rest.AbsoluteURL(goa.ContextRequest(ctx), app.SpaceHref(spaceID.String())) // copy all fields from remoteworkitem into result workitem // creator // associate the identities to the work item // ignore here, it is being processed above // assignees // associate the identities to the work item // ignore here, it is being processed above // copy other fields