Skip to content

Commit

Permalink
Merge pull request #1962 from eliasbruvik/FIX-1910
Browse files Browse the repository at this point in the history
FIX-1910 Search by objects
  • Loading branch information
eliasbruvik committed Jun 22, 2023
2 parents e40d6c3 + b42ca9d commit ab7ce31
Show file tree
Hide file tree
Showing 14 changed files with 611 additions and 140 deletions.
6 changes: 6 additions & 0 deletions Src/WitsmlExplorer.Api/HttpHandlers/ObjectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ namespace WitsmlExplorer.Api.HttpHandlers
{
public static class ObjectHandler
{
[Produces(typeof(ObjectOnWellbore[]))]
public static async Task<IResult> GetObjectsByType(EntityType objectType, IObjectService objectService)
{
return TypedResults.Ok(await objectService.GetObjectsByType(objectType));
}

[Produces(typeof(ObjectOnWellbore[]))]
public static async Task<IResult> GetObjectsIdOnly(string wellUid, string wellboreUid, EntityType objectType, IObjectService objectService)
{
Expand Down
12 changes: 12 additions & 0 deletions Src/WitsmlExplorer.Api/Query/ObjectQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public static IEnumerable<T> CopyObjectsQuery<T>(IEnumerable<T> objects, WitsmlW
});
}

public static IWitsmlObjectList GetWitsmlObjectsByType(EntityType type)
{
IWitsmlObjectList list = EntityTypeHelper.ToObjectList(type);
WitsmlObjectOnWellbore o = EntityTypeHelper.ToObjectOnWellbore(type);
o.UidWell = "";
o.UidWellbore = "";
o.Uid = "";
o.Name = "";
list.Objects = new[] { o };
return list;
}

public static IWitsmlObjectList GetWitsmlObjectsByIds(string wellUid, string wellboreUid, string[] objectUids, EntityType type)
{
IWitsmlObjectList list = EntityTypeHelper.ToObjectList(type);
Expand Down
2 changes: 2 additions & 0 deletions Src/WitsmlExplorer.Api/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public static void ConfigureApi(this WebApplication app, IConfiguration configur
app.MapGet("/wells", WellHandler.GetAllWells, useOAuth2);
app.MapGet("/wells/{wellUid}", WellHandler.GetWell, useOAuth2);

app.MapGet("/objects/{objectType}", ObjectHandler.GetObjectsByType, useOAuth2);

app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}", WellboreHandler.GetWellbore, useOAuth2);
app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/idonly/{objectType}", ObjectHandler.GetObjectsIdOnly, useOAuth2);
app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/idonly/{objectType}/{objectUid}", ObjectHandler.GetObjectIdOnly, useOAuth2);
Expand Down
25 changes: 25 additions & 0 deletions Src/WitsmlExplorer.Api/Services/ObjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace WitsmlExplorer.Api.Services
{
public interface IObjectService
{
Task<IEnumerable<ObjectOnWellbore>> GetObjectsByType(EntityType objectType);
Task<IEnumerable<ObjectOnWellbore>> GetObjectsIdOnly(string wellUid, string wellboreUid, EntityType objectType);
Task<IEnumerable<ObjectOnWellbore>> GetObjectIdOnly(string wellUid, string wellboreUid, string objectUid, EntityType objectType);
Task<Dictionary<EntityType, int>> GetExpandableObjectsCount(string wellUid, string wellboreUid);
Expand All @@ -30,6 +31,30 @@ public ObjectService(IWitsmlClientProvider witsmlClientProvider, ILogger<ObjectS
_logger = logger;
}

public async Task<IEnumerable<ObjectOnWellbore>> GetObjectsByType(EntityType objectType)
{
if (EntityTypeHelper.ToObjectOnWellbore(objectType) == null)
{
throw new ArgumentException($"{nameof(objectType)} must be a valid type of an object on wellbore");
}
IWitsmlObjectList query = ObjectQueries.GetWitsmlObjectsByType(objectType);
IWitsmlObjectList result = await _witsmlClient.GetFromStoreNullableAsync(query, new OptionsIn(ReturnElements.Requested));
if (result?.Objects == null)
{
return new List<ObjectOnWellbore>();
}

return result.Objects.Select((obj) =>
new ObjectOnWellbore()
{
Uid = obj.Uid,
WellboreUid = obj.UidWellbore,
WellUid = obj.UidWell,
Name = obj.Name,
}
);
}

public async Task<IEnumerable<ObjectOnWellbore>> GetObjectsIdOnly(string wellUid, string wellboreUid, EntityType objectType)
{
return await GetObjectIdOnly(wellUid, wellboreUid, "", objectType);
Expand Down
Loading

0 comments on commit ab7ce31

Please sign in to comment.