func ConvertJSONAPIToWorkItem(appl application.Application, source app.WorkItem, target *workitem.WorkItem) error {
	// construct default values from input WI
	version, err := getVersion(source.Attributes["version"])
	if err != nil {
		return err
	}
	target.Version = version

	if source.Relationships != nil && source.Relationships.Assignees != nil {
		if source.Relationships.Assignees.Data == nil {
			delete(target.Fields, workitem.SystemAssignees)
		} else {
			var ids []string
			for _, d := range source.Relationships.Assignees.Data {
				assigneeUUID, err := uuid.FromString(*d.ID)
				if err != nil {
					return errors.NewBadParameterError("data.relationships.assignees.data.id", *d.ID)
				}
				if ok := appl.Identities().IsValid(context.Background(), assigneeUUID); !ok {
					return errors.NewBadParameterError("data.relationships.assignees.data.id", *d.ID)
				}
				ids = append(ids, assigneeUUID.String())
			}
			target.Fields[workitem.SystemAssignees] = ids
		}
	}
	if source.Relationships != nil && source.Relationships.Iteration != nil {
		if source.Relationships.Iteration.Data == nil {
			delete(target.Fields, workitem.SystemIteration)
		} else {
			d := source.Relationships.Iteration.Data
			iterationUUID, err := uuid.FromString(*d.ID)
			if err != nil {
				return errors.NewBadParameterError("data.relationships.iteration.data.id", *d.ID)
			}
			if _, err = appl.Iterations().Load(context.Background(), iterationUUID); err != nil {
				return errors.NewBadParameterError("data.relationships.iteration.data.id", *d.ID)
			}
			target.Fields[workitem.SystemIteration] = iterationUUID.String()
		}
	}
	if source.Relationships != nil && source.Relationships.Area != nil {
		if source.Relationships.Area.Data == nil {
			delete(target.Fields, workitem.SystemArea)
		} else {
			d := source.Relationships.Area.Data
			areaUUID, err := uuid.FromString(*d.ID)
			if err != nil {
				return errors.NewBadParameterError("data.relationships.area.data.id", *d.ID)
			}
			if _, err = appl.Areas().Load(context.Background(), areaUUID); err != nil {
				return errors.NewBadParameterError("data.relationships.area.data.id", *d.ID)
			}
			target.Fields[workitem.SystemArea] = areaUUID.String()
		}
	}
	if source.Relationships != nil && source.Relationships.BaseType != nil {
		if source.Relationships.BaseType.Data != nil {
			target.Type = source.Relationships.BaseType.Data.ID
		}
	}

	for key, val := range source.Attributes {
		// convert legacy description to markup content
		if key == workitem.SystemDescription {
			if m := rendering.NewMarkupContentFromValue(val); m != nil {
				target.Fields[key] = *m
			}
		} else if key == workitem.SystemCodebase {
			if m, err := codebase.NewCodebaseContentFromValue(val); err == nil {
				target.Fields[key] = *m
			} else {
				return err
			}
		} else {
			target.Fields[key] = val
		}
	}
	if description, ok := target.Fields[workitem.SystemDescription].(rendering.MarkupContent); ok {
		// verify the description markup
		if !rendering.IsMarkupSupported(description.Markup) {
			return errors.NewBadParameterError("data.relationships.attributes[system.description].markup", description.Markup)
		}
	}
	return nil
}
// ConvertJSONAPIToWorkItem is responsible for converting given WorkItem model object into a
// response resource object by jsonapi.org specifications
ConvertJSONAPIToWorkItem is responsible for converting given WorkItem model object into a
response resource object by jsonapi.org specifications
// ConvertJSONAPIToWorkItem is responsible for converting given WorkItem model object into a // response resource object by jsonapi . org specifications
func ConvertJSONAPIToWorkItem(appl application.Application, source app.WorkItem, target *workitem.WorkItem) error {
	version, err := getVersion(source.Attributes["version"])
	if err != nil {
		return err
	}
	target.Version = version
	if source.Relationships != nil && source.Relationships.Assignees != nil {
		if source.Relationships.Assignees.Data == nil {
			delete(target.Fields, workitem.SystemAssignees)
		} else {
			var ids []string
			for _, d := range source.Relationships.Assignees.Data {
				assigneeUUID, err := uuid.FromString(*d.ID)
				if err != nil {
					return errors.NewBadParameterError("data.relationships.assignees.data.id", *d.ID)
				}
				if ok := appl.Identities().IsValid(context.Background(), assigneeUUID); !ok {
					return errors.NewBadParameterError("data.relationships.assignees.data.id", *d.ID)
				}
				ids = append(ids, assigneeUUID.String())
			}
			target.Fields[workitem.SystemAssignees] = ids
		}
	}
	if source.Relationships != nil && source.Relationships.Iteration != nil {
		if source.Relationships.Iteration.Data == nil {
			delete(target.Fields, workitem.SystemIteration)
		} else {
			d := source.Relationships.Iteration.Data
			iterationUUID, err := uuid.FromString(*d.ID)
			if err != nil {
				return errors.NewBadParameterError("data.relationships.iteration.data.id", *d.ID)
			}
			if _, err = appl.Iterations().Load(context.Background(), iterationUUID); err != nil {
				return errors.NewBadParameterError("data.relationships.iteration.data.id", *d.ID)
			}
			target.Fields[workitem.SystemIteration] = iterationUUID.String()
		}
	}
	if source.Relationships != nil && source.Relationships.Area != nil {
		if source.Relationships.Area.Data == nil {
			delete(target.Fields, workitem.SystemArea)
		} else {
			d := source.Relationships.Area.Data
			areaUUID, err := uuid.FromString(*d.ID)
			if err != nil {
				return errors.NewBadParameterError("data.relationships.area.data.id", *d.ID)
			}
			if _, err = appl.Areas().Load(context.Background(), areaUUID); err != nil {
				return errors.NewBadParameterError("data.relationships.area.data.id", *d.ID)
			}
			target.Fields[workitem.SystemArea] = areaUUID.String()
		}
	}
	if source.Relationships != nil && source.Relationships.BaseType != nil {
		if source.Relationships.BaseType.Data != nil {
			target.Type = source.Relationships.BaseType.Data.ID
		}
	}
	for key, val := range source.Attributes {
		if key == workitem.SystemDescription {
			if m := rendering.NewMarkupContentFromValue(val); m != nil {
				target.Fields[key] = *m
			}
		} else if key == workitem.SystemCodebase {
			if m, err := codebase.NewCodebaseContentFromValue(val); err == nil {
				target.Fields[key] = *m
			} else {
				return err
			}
		} else {
			target.Fields[key] = val
		}
	}
	if description, ok := target.Fields[workitem.SystemDescription].(rendering.MarkupContent); ok {
		if !rendering.IsMarkupSupported(description.Markup) {
			return errors.NewBadParameterError("data.relationships.attributes[system.description].markup", description.Markup)
		}
	}
	return nil
}
func ConvertJSONAPIToWorkItem ( appl application . Application , source app . WorkItem , target * workitem . WorkItem ) error { version , err := getVersion ( source . Attributes [ " " ] ) if err != nil { return err } target . Version = version if source . Relationships != nil && source . Relationships . Assignees != nil { if source . Relationships . Assignees . Data == nil { delete ( target . Fields , workitem . SystemAssignees ) } else { var ids [ ] string for _ , d := range source . Relationships . Assignees . Data { assigneeUUID , err := uuid . FromString ( * d . ID ) if err != nil { return errors . NewBadParameterError ( " " , * d . ID ) } if ok := appl . Identities ( ) . IsValid ( context . Background ( ) , assigneeUUID ) ; ! ok { return errors . NewBadParameterError ( " " , * d . ID ) } ids = append ( ids , assigneeUUID . String ( ) ) } target . Fields [ workitem . SystemAssignees ] = ids } } if source . Relationships != nil && source . Relationships . Iteration != nil { if source . Relationships . Iteration . Data == nil { delete ( target . Fields , workitem . SystemIteration ) } else { d := source . Relationships . Iteration . Data iterationUUID , err := uuid . FromString ( * d . ID ) if err != nil { return errors . NewBadParameterError ( " " , * d . ID ) } if _ , err = appl . Iterations ( ) . Load ( context . Background ( ) , iterationUUID ) ; err != nil { return errors . NewBadParameterError ( " " , * d . ID ) } target . Fields [ workitem . SystemIteration ] = iterationUUID . String ( ) } } if source . Relationships != nil && source . Relationships . Area != nil { if source . Relationships . Area . Data == nil { delete ( target . Fields , workitem . SystemArea ) } else { d := source . Relationships . Area . Data areaUUID , err := uuid . FromString ( * d . ID ) if err != nil { return errors . NewBadParameterError ( " " , * d . ID ) } if _ , err = appl . Areas ( ) . Load ( context . Background ( ) , areaUUID ) ; err != nil { return errors . NewBadParameterError ( " " , * d . ID ) } target . Fields [ workitem . SystemArea ] = areaUUID . String ( ) } } if source . Relationships != nil && source . Relationships . BaseType != nil { if source . Relationships . BaseType . Data != nil { target . Type = source . Relationships . BaseType . Data . ID } } for key , val := range source . Attributes { if key == workitem . SystemDescription { if m := rendering . NewMarkupContentFromValue ( val ) ; m != nil { target . Fields [ key ] = * m } } else if key == workitem . SystemCodebase { if m , err := codebase . NewCodebaseContentFromValue ( val ) ; err == nil { target . Fields [ key ] = * m } else { return err } } else { target . Fields [ key ] = val } } if description , ok := target . Fields [ workitem . SystemDescription ] . ( rendering . MarkupContent ) ; ok { if ! rendering . IsMarkupSupported ( description . Markup ) { return errors . NewBadParameterError ( " " , description . Markup ) } } return nil }
ConvertJSONAPIToWorkItem is responsible for converting given WorkItem model object into a
response resource object by jsonapi.org specifications
ConvertJSONAPIToWorkItem is responsible for converting given WorkItem model object into a response resource object by jsonapi . org specifications
// construct default values from input WI // convert legacy description to markup content // verify the description markup