forked from equinor/witsml-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the Attachment object💡 equinor#2616
- Loading branch information
1 parent
d51c31f
commit 5b789ce
Showing
10 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Xml.Serialization; | ||
|
||
using Witsml.Data.Measures; | ||
using Witsml.Extensions; | ||
|
||
namespace Witsml.Data | ||
{ | ||
public class WitsmlAttachment : WitsmlObjectOnWellbore | ||
{ | ||
public override WitsmlAttachments AsItemInWitsmlList() | ||
{ | ||
return new WitsmlAttachments() | ||
{ | ||
Attachments = this.AsItemInList() | ||
}; | ||
} | ||
|
||
[XmlElement("objectReference")] | ||
public WitsmlObjectReference ObjectReference { get; set; } | ||
|
||
[XmlElement("fileName")] | ||
public string FileName { get; set; } | ||
|
||
[XmlElement("description")] | ||
public string Description { get; set; } | ||
|
||
[XmlElement("fileType")] | ||
public string FileType { get; set; } | ||
|
||
[XmlElement("content")] | ||
public string Content { get; set; } | ||
|
||
[XmlElement("commonData")] | ||
public WitsmlCommonData CommonData { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Mail; | ||
using System.Xml.Serialization; | ||
|
||
namespace Witsml.Data | ||
{ | ||
[XmlRoot("attachments", Namespace = "http://www.witsml.org/schemas/1series")] | ||
public class WitsmlAttachments : IWitsmlObjectList | ||
{ | ||
[XmlAttribute("version")] | ||
public string Version = "1.4.1.1"; | ||
|
||
[XmlElement("attachment")] | ||
public List<WitsmlAttachment> Attachments { get; set; } = new (); | ||
|
||
public string TypeName => "attachment"; | ||
|
||
[XmlIgnore] | ||
public IEnumerable<WitsmlObjectOnWellbore> Objects | ||
{ | ||
get => Attachments; | ||
set => Attachments = value.Select(obj => (WitsmlAttachment)obj).ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Witsml.Data; | ||
using Witsml.Data.Measures; | ||
using Witsml.Data.Rig; | ||
|
||
using WitsmlExplorer.Api.Models.Measure; | ||
using WitsmlExplorer.Api.Services; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class Attachment : ObjectOnWellbore | ||
{ | ||
public string FileName { get; set; } | ||
public string Description { get; set; } | ||
public string FileType { get; set; } | ||
public string Content { get; set; } | ||
public CommonData CommonData { get; set; } | ||
public override WitsmlAttachments ToWitsml() | ||
{ | ||
return new WitsmlAttachment | ||
{ | ||
UidWell = WellUid, | ||
NameWell = WellName, | ||
UidWellbore = WellboreUid, | ||
NameWellbore = WellboreName, | ||
Uid = Uid, | ||
Name = Name, | ||
FileName = FileName, | ||
Description = Description, | ||
FileType = FileType, | ||
Content = Content, | ||
CommonData = CommonData?.ToWitsml() | ||
}.AsItemInWitsmlList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Witsml.Data; | ||
using Witsml.Data.Measures; | ||
using Witsml.Extensions; | ||
|
||
using WitsmlExplorer.Api.Jobs.Common; | ||
|
||
namespace WitsmlExplorer.Api.Query | ||
{ | ||
public static class AttachmentQueries | ||
{ | ||
public static WitsmlAttachments GetWitsmlAttachment(string wellUid, string wellboreUid, string attachmentUid = "") | ||
{ | ||
return new WitsmlAttachments | ||
{ | ||
Attachments = new WitsmlAttachment | ||
{ | ||
Uid = attachmentUid, | ||
UidWell = wellUid, | ||
UidWellbore = wellboreUid, | ||
NameWell = "", | ||
NameWellbore = "", | ||
Name = "", | ||
FileName = "", | ||
Description = "", | ||
FileType = "", | ||
Content = "", | ||
CommonData = new WitsmlCommonData() | ||
{ | ||
ItemState = "", | ||
SourceName = "", | ||
DTimLastChange = "", | ||
DTimCreation = "", | ||
ServiceCategory = "", | ||
Comments = "", | ||
DefaultDatum = "", | ||
} | ||
}.AsItemInList() | ||
}; | ||
} | ||
|
||
public static WitsmlAttachments QueryById(string wellUid, string wellboreUid, string attachmentUid) | ||
{ | ||
return new WitsmlAttachments() | ||
{ | ||
Attachments = new WitsmlAttachment | ||
{ | ||
Uid = attachmentUid, | ||
UidWell = wellUid, | ||
UidWellbore = wellboreUid | ||
}.AsItemInList() | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using Witsml.Data; | ||
using Witsml.ServiceReference; | ||
|
||
using WitsmlExplorer.Api.Models; | ||
using WitsmlExplorer.Api.Models.Measure; | ||
using WitsmlExplorer.Api.Query; | ||
|
||
namespace WitsmlExplorer.Api.Services | ||
{ | ||
public interface IAttachmentService | ||
{ | ||
Task<Attachment> GetAttachment(string wellUid, string wellboreUid, string attachmentUid); | ||
Task<ICollection<Attachment>> GetAttachments(string wellUid, string wellboreUid); | ||
} | ||
|
||
public class AttachmentService : WitsmlService, IAttachmentService | ||
{ | ||
public AttachmentService(IWitsmlClientProvider witsmlClientProvider) : base(witsmlClientProvider) { } | ||
|
||
public async Task<Attachment> GetAttachment(string wellUid, string wellboreUid, string attachmentUid) | ||
{ | ||
WitsmlAttachments query = AttachmentQueries.GetWitsmlAttachment(wellUid, wellboreUid, attachmentUid); | ||
WitsmlAttachments result = await _witsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.All)); | ||
return WitsmlToAttachment(result.Attachments.FirstOrDefault()); | ||
} | ||
public async Task<ICollection<Attachment>> GetAttachments(string wellUid, string wellboreUid) | ||
{ | ||
WitsmlAttachments witsmlAttachments = AttachmentQueries.GetWitsmlAttachment(wellUid, wellboreUid); | ||
WitsmlAttachments result = await _witsmlClient.GetFromStoreAsync(witsmlAttachments, new OptionsIn(ReturnElements.Requested)); | ||
return result.Attachments.Select(WitsmlToAttachment).OrderBy(attachment => attachment.Name).ToList(); | ||
} | ||
|
||
private static Attachment WitsmlToAttachment(WitsmlAttachment attachment) | ||
{ | ||
return attachment == null ? null : new Attachment | ||
{ | ||
Uid = attachment.Uid, | ||
Name = attachment.Name, | ||
WellUid = attachment.UidWell, | ||
WellName = attachment.NameWell, | ||
WellboreName = attachment.NameWellbore, | ||
WellboreUid = attachment.UidWellbore, | ||
FileName = attachment.FileName, | ||
Description = attachment.Description, | ||
FileType = attachment.FileType, | ||
Content = attachment.Content, | ||
CommonData = new CommonData() | ||
{ | ||
ItemState = attachment.CommonData.ItemState, | ||
SourceName = attachment.CommonData.SourceName, | ||
DTimLastChange = attachment.CommonData.DTimLastChange, | ||
DTimCreation = attachment.CommonData.DTimCreation, | ||
ServiceCategory = attachment.CommonData.ServiceCategory, | ||
Comments = attachment.CommonData.Comments, | ||
DefaultDatum = attachment.CommonData.DefaultDatum, | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Tests/WitsmlExplorer.IntegrationTests/Resources/attachment.xml
Large diffs are not rendered by default.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
Tests/WitsmlExplorer.IntegrationTests/Witsml/GetFromStore/AttachmentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Threading.Tasks; | ||
|
||
using Witsml; | ||
using Witsml.Data; | ||
using Witsml.ServiceReference; | ||
using Witsml.Xml; | ||
|
||
using WitsmlExplorer.Api.Query; | ||
|
||
using Xunit; | ||
|
||
namespace WitsmlExplorer.IntegrationTests.Witsml.GetFromStore | ||
{ | ||
public partial class AttachmentTests | ||
{ | ||
private readonly WitsmlClient _client; | ||
|
||
public AttachmentTests() | ||
{ | ||
WitsmlConfiguration config = ConfigurationReader.GetWitsmlConfiguration(); | ||
_client = new WitsmlClient(options => | ||
{ | ||
options.Hostname = config.Hostname; | ||
options.Credentials = new WitsmlCredentials(config.Username, config.Password); | ||
}); | ||
} | ||
|
||
[Fact(Skip = "Should only be run manually")] | ||
public async Task GetAttachmentSerializesCorrectly() | ||
{ | ||
// if the following attachment does not exit, add the file attachment to the server manually | ||
// this affects wellUid, wellboreUid, nameWell, and nameWellbore values during comparison so adjust them here and in the file accordingly | ||
string wellUid = "8c77de13-4fad-4b2e-ba3d-7e6b0e35a394"; | ||
string wellboreUid = "ae75db48-5cef-4bd1-9ddf-6035b0d2cd49"; | ||
string attachmentUid = "attachmentUid"; | ||
WitsmlAttachments queryExisting = AttachmentQueries.GetWitsmlAttachment(wellUid, wellboreUid, attachmentUid); | ||
WitsmlAttachments serverAttachment = await _client.GetFromStoreAsync(queryExisting, new OptionsIn(ReturnElements.All)); | ||
string responseXml = XmlHelper.Serialize(serverAttachment); | ||
string serverAttachmentXml = TestUtils.CleanResponse(responseXml); | ||
string fileAttachmentXml = TestUtils.GetTestXml("Attachment"); | ||
Assert.Equal(fileAttachmentXml, serverAttachmentXml); | ||
} | ||
} | ||
} |