public ModelEnvelope <FieldBoundary> Convert(FieldBoundaryDto fieldBoundaryDto) { var fieldBoundary = new FieldBoundary { TimeScopes = new List <TimeScope>() { new TimeScope { TimeStamp1 = new DateTime(fieldBoundaryDto.CropYear, 1, 1), TimeStamp2 = new DateTime(fieldBoundaryDto.CropYear, 12, 31) } }, Description = $"{fieldBoundaryDto.CropYear} Boundary" }; var fieldBoundaryUniqueId = fieldBoundary.Id; var boundaryUniqueId = _uniqueIdFactory.CreateInt(fieldBoundaryDto.Id); fieldBoundaryUniqueId.UniqueIds.Add(boundaryUniqueId); var selfLink = new ReferenceLink { Id = fieldBoundaryUniqueId, Rel = Relationships.Self, Link = $"/FieldBoundaries/{boundaryUniqueId.Source}/{boundaryUniqueId.Id}" }; var fieldUniqueId = _uniqueIdFactory.CreateGuid(fieldBoundaryDto.FieldUid); var fieldCompoundId = fieldUniqueId.ToCompoundIdentifier(); fieldBoundary.FieldId = fieldCompoundId.ReferenceId; var fieldLink = new ReferenceLink { Id = fieldCompoundId, Rel = typeof(Field).ObjectRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; // NOTE: Skipped SpatialData to not introduce Spatial Dependencies in conversion. var fieldBoundaryEnvelope = new ModelEnvelope <FieldBoundary>(fieldBoundary); fieldBoundaryEnvelope.Links.Add(selfLink); fieldBoundaryEnvelope.Links.Add(fieldLink); return(fieldBoundaryEnvelope); }
public ModelEnvelope <Farm> Convert(FarmDto farmDto) { var farm = new Farm() { Description = farmDto.Name }; var farmUniqueId = _uniqueIdFactory.CreateGuid(farmDto.Uid); var farmCompoundId = farm.Id; farmCompoundId.UniqueIds.Add(farmUniqueId); var selfLink = new ReferenceLink { Id = farmCompoundId, Rel = Relationships.Self, Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}", Type = "get" }; var growerUniqueId = _uniqueIdFactory.CreateGuid(farmDto.GrowerUid); var growerCompoundId = growerUniqueId.ToCompoundIdentifier(); farm.GrowerId = growerCompoundId.ReferenceId; var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = typeof(Grower).ObjectRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}", Type = "get" }; var fieldsLink = new ReferenceLink { Rel = typeof(Field).ListRel(), Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}/Fields", Type = "get" }; var farmEnvelope = new ModelEnvelope <Farm>(farm); farmEnvelope.Links.Add(growerLink); farmEnvelope.Links.Add(selfLink); farmEnvelope.Links.Add(fieldsLink); return(farmEnvelope); }
public ModelEnvelope <CropZone> Convert(CropZoneDto cropZoneDto) { var cropZone = new CropZone() { Description = cropZoneDto.Name, TimeScopes = new List <TimeScope>() { new TimeScope { TimeStamp1 = new DateTime(cropZoneDto.CropYear, 1, 1), TimeStamp2 = new DateTime(cropZoneDto.CropYear, 12, 31) } } }; var cropZoneUniqueId = _uniqueIdFactory.CreateInt(cropZoneDto.Id); var cropZoneCompoundId = cropZone.Id; cropZone.Id.UniqueIds.Add(cropZoneUniqueId); var selfLink = new ReferenceLink { Id = cropZoneCompoundId, Rel = Relationships.Self, Link = $"/CropZones/{cropZoneUniqueId.Source}/{cropZoneUniqueId.Id}" }; var fieldUniqueId = _uniqueIdFactory.CreateGuid(cropZoneDto.FieldUid); var fieldCompoundId = fieldUniqueId.ToCompoundIdentifier(); var fieldLink = new ReferenceLink { Id = fieldCompoundId, Rel = typeof(Field).Name.ToLower(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; cropZone.FieldId = fieldCompoundId.ReferenceId; // NOTE: Skipped BoundingRegion to not introduce Spatial Dependencies in conversion. var cropZoneEnvelope = new ModelEnvelope <CropZone>(cropZone); cropZoneEnvelope.Links.Add(selfLink); cropZoneEnvelope.Links.Add(fieldLink); return(cropZoneEnvelope); }
public ModelEnvelope <Grower> Convert(GrowerDto pmGrower) { var grower = new Grower() { Name = pmGrower.Name }; var growerCompoundId = grower.Id; var growerUniqueId = _uniqueIdFactory.CreateGuid(pmGrower.Uid); growerCompoundId.UniqueIds.Add(growerUniqueId); var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = Relationships.Self, Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}", Type = "get" }; var farmsLink = new ReferenceLink { Rel = typeof(Farm).ListRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}/Farms" }; var fieldsLink = new ReferenceLink { Rel = typeof(Field).ListRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}/Fields" }; grower.Id.UniqueIds.Add(growerUniqueId); var growerEnvelope = new ModelEnvelope <Grower>(grower); growerEnvelope.Links.Add(growerLink); growerEnvelope.Links.Add(farmsLink); growerEnvelope.Links.Add(fieldsLink); return(growerEnvelope); }
public ModelEnvelope <Field> Convert(FieldDto fieldDto) { if (fieldDto == null) { return(null); } var field = new Field() { Description = fieldDto.Name }; var fieldCompoundId = field.Id; var fieldUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.Uid); fieldCompoundId.UniqueIds.Add(fieldUniqueId); var farmUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.FarmUid); var farmCompoundId = farmUniqueId.ToCompoundIdentifier(); field.FarmId = farmCompoundId.ReferenceId; var growerUniqueId = _uniqueIdFactory.CreateGuid(fieldDto.GrowerUid); var growerCompoundId = growerUniqueId.ToCompoundIdentifier(); var selfLink = new ReferenceLink { Id = fieldCompoundId, Rel = Relationships.Self, Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}" }; var growerLink = new ReferenceLink { Id = growerCompoundId, Rel = typeof(Grower).ObjectRel(), Link = $"/Growers/{growerUniqueId.Source}/{growerUniqueId.Id}" }; var farmLink = new ReferenceLink { Id = farmCompoundId, Rel = typeof(Farm).ObjectRel(), Link = $"/Farms/{farmUniqueId.Source}/{farmUniqueId.Id}" }; var cropZonesLink = new ReferenceLink { Rel = typeof(CropZone).ListRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}/CropZones" }; var boundaryLink = new ReferenceLink { Rel = typeof(FieldBoundary).ListRel(), Link = $"/Fields/{fieldUniqueId.Source}/{fieldUniqueId.Id}/FieldBoundaries" }; field.Id.UniqueIds.Add(fieldUniqueId); var fieldEnvelope = new ModelEnvelope <Field>(field); fieldEnvelope.Links.Add(selfLink); fieldEnvelope.Links.Add(growerLink); fieldEnvelope.Links.Add(farmLink); fieldEnvelope.Links.Add(cropZonesLink); fieldEnvelope.Links.Add(boundaryLink); return(fieldEnvelope); }