Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using GSF.Data;
using GSF.Data.Model;
using GSF.Web.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using openXDA.Model;
using SystemCenter.Model;
Expand All @@ -57,16 +58,18 @@ private class extendedAssetGroupView: AssetGroupView

}

[HttpGet, Route("{assetGroupID:int}/Assets")]
public IHttpActionResult GetAssets(int assetGroupID)
[HttpPost, Route("{assetGroupID:int}/Assets/{page:int}")]
public IHttpActionResult GetAssets([FromBody] PostData postData, [FromUri] int assetGroupID, [FromUri] int page)
{
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
{
try
{
string sql = @"SELECT
int recordsPerPage = PageSize ?? 50;

string sql = @$"SELECT
DISTINCT
Asset.ID,
AssetAssetGroup.AssetGroupID,
Expand All @@ -91,9 +94,30 @@ GROUP BY
Asset.VoltageKV,
AssetType.Name,
AssetAssetGroup.AssetGroupID
HAVING AssetAssetGroup.AssetGroupID = {0}";
HAVING AssetAssetGroup.AssetGroupID = {{0}}
ORDER BY {postData.OrderBy} {(postData.Ascending ? "ASC" : "DESC")}
OFFSET {recordsPerPage * page} ROWS
FETCH NEXT {recordsPerPage} ROWS ONLY
";

string countSql = @"SELECT
COUNT(DISTINCT AssetID)
FROM
AssetAssetGroup
WHERE
AssetGroupID = {0}";

int count = connection.ExecuteScalar<int>(countSql, assetGroupID);

return Ok(connection.RetrieveData(sql,assetGroupID));
DataTable results = connection.RetrieveData(sql, assetGroupID);

return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(results),
NumberOfPages = (count + recordsPerPage - 1) / recordsPerPage,
TotalRecords = count,
RecordsPerPage = recordsPerPage
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -159,16 +183,18 @@ public IHttpActionResult RemoveAsset(int assetGroupID, int assetID)
}
}

[HttpGet, Route("{assetGroupID:int}/Meters")]
public IHttpActionResult GetMeters(int assetGroupID)
[HttpPost, Route("{assetGroupID:int}/Meters/{page:int}")]
public IHttpActionResult GetMeters([FromBody] PostData postData, [FromUri] int assetGroupID, [FromUri] int page)
{
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
{
try
{
string sql = @"SELECT DISTINCT
int recordsPerPage = PageSize ?? 50;

string sql = @$"SELECT DISTINCT
Meter.ID,
MeterAssetGroup.AssetGroupID,
Meter.AssetKey,
Expand All @@ -177,6 +203,28 @@ public IHttpActionResult GetMeters(int assetGroupID)
Meter.Model,
Location.Name as Location,
COUNT(DISTINCT MeterAsset.AssetID) as MappedAssets
FROM
Meter LEFT JOIN
Location ON Meter.LocationID = Location.ID LEFT JOIN
MeterAsset ON Meter.ID = MeterAsset.MeterID LEFT JOIN
Asset ON MeterAsset.AssetID = Asset.ID LEFT JOIN
MeterAssetGroup ON Meter.ID = MeterAssetGroup.MeterID
GROUP BY
Meter.ID,
Meter.AssetKey,
Meter.Name,
Meter.Make,
Meter.Model,
Location.Name,
MeterAssetGroup.AssetGroupID
HAVING MeterAssetGroup.AssetGroupID = {{0}}
ORDER BY {postData.OrderBy} {(postData.Ascending ? "ASC" : "DESC")}
OFFSET {recordsPerPage * page} ROWS
FETCH NEXT {recordsPerPage} ROWS ONLY"
;

string countSql = @"SELECT
COUNT(DISTINCT Meter.ID)
FROM
Meter LEFT JOIN
Location ON Meter.LocationID = Location.ID LEFT JOIN
Expand All @@ -193,7 +241,17 @@ GROUP BY
MeterAssetGroup.AssetGroupID
HAVING MeterAssetGroup.AssetGroupID = {0}";

return Ok(connection.RetrieveData(sql,assetGroupID));
int count = connection.ExecuteScalar<int>(countSql, assetGroupID);

DataTable results = connection.RetrieveData(sql, assetGroupID);

return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(results),
TotalRecords = count,
RecordsPerPage = recordsPerPage,
NumberOfPages = (count + recordsPerPage - 1) / recordsPerPage
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -283,18 +341,32 @@ public IHttpActionResult GetUserAccounts(int assetGroupID)
return Unauthorized();
}

[HttpGet, Route("{assetGroupID:int}/AssetGroups")]
public IHttpActionResult GetSubGroups(int assetGroupID)
[HttpPost, Route("{assetGroupID:int}/AssetGroups/{page:int}")]
public IHttpActionResult GetSubGroupsPaged([FromBody] PostData postData, [FromUri] int assetGroupID, [FromUri] int page)
{
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
{
try
{
IEnumerable<AssetGroupView> records = new TableOperations<AssetGroupView>(connection).QueryRecordsWhere("ID in (SELECT ChildAssetGroupID FROM AssetGroupAssetGroupView WHERE ParentAssetGroupID = {0})", assetGroupID);
int recordsPerPage = PageSize ?? 50;

return Ok(records);
TableOperations<AssetGroupView> table = new TableOperations<AssetGroupView>(connection);

RecordRestriction recordRestriction = new RecordRestriction("ID in (SELECT ChildAssetGroupID FROM AssetGroupAssetGroupView WHERE ParentAssetGroupID = {0})", assetGroupID);

int count = table.QueryRecordCount(recordRestriction);

IEnumerable<AssetGroupView> records = new TableOperations<AssetGroupView>(connection).QueryRecords(postData.OrderBy, postData.Ascending, page + 1, recordsPerPage, recordRestriction);

return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(records),
TotalRecords = count,
RecordsPerPage = recordsPerPage,
NumberOfPages = (count + recordsPerPage - 1) / recordsPerPage
});
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public IHttpActionResult GetAssetLocationsPaged([FromBody] PostData postData, [F
if (!GetAuthCheck())
return Unauthorized();

int recordsPerPage = Take ?? 50;
int recordsPerPage = PageSize ?? 50;

PagedResults results = new PagedResults();

Expand Down Expand Up @@ -164,7 +164,7 @@ public IHttpActionResult GetAssetMetersPaged([FromBody] PostData postData, [From
{
try
{
int recordsPerPage = Take ?? 50;
int recordsPerPage = PageSize ?? 50;

string[] sortFields = { "AssetKey", "Name", "Make", "Model" };

Expand Down Expand Up @@ -204,7 +204,7 @@ public IHttpActionResult GetAssetAssetConnections([FromBody] PostData postData,
{
try
{
int recordsPerPage = Take ?? 50;
int recordsPerPage = PageSize ?? 50;

string[] sortFields = { "AssetName", "AssetKey", "Name" };

Expand Down Expand Up @@ -686,15 +686,17 @@ public IHttpActionResult PostExistingMeterForAsset(int assetID, int meterID)
}
}

[HttpGet, Route("{assetID:int}/ConnectedChannels")]
public IHttpActionResult GetAssetChannels(int assetID)
[HttpPost, Route("{assetID:int}/ConnectedChannels/{page:int}")]
public IHttpActionResult GetAssetChannels([FromBody] PostData postData, [FromUri] int assetID, [FromUri] int page)
{
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
try
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
{
int recordsPerPage = PageSize ?? 50;

Asset asset = new TableOperations<Asset>(connection).QueryRecordWhere("ID={0}", assetID);
if (asset is null)
throw (new Exception($"Asset ID={assetID} not found in OpenXDA database"));
Expand All @@ -706,17 +708,43 @@ public IHttpActionResult GetAssetChannels(int assetID)

if (connectedChannels.Count > 0)
{
TableOperations<ChannelDetail> tableOp = new TableOperations<ChannelDetail>(connection);
// Channels get triplicated from Series Type ID in ChannelDetail View
IEnumerable<ChannelDetail> uniqueChannels = new TableOperations<ChannelDetail>(connection)
.QueryRecordsWhere($"ID in ({string.Join(", ", connectedChannels.Select(channels => channels.ID))})")
.DistinctBy(c => c.ID);

return Ok(uniqueChannels);
string countSql = $@"
SELECT COUNT(*)
FROM ChannelDetail
WHERE ID in ({string.Join(", ", connectedChannels.Select(channels => channels.ID))})
";

string sql = @$"
SELECT *
FROM ChannelDetail
WHERE ID in ({string.Join(", ", connectedChannels.Select(channels => channels.ID))})
ORDER BY {postData.OrderBy} {(postData.Ascending ? "ASC" : "DESC")}
OFFSET {page * recordsPerPage} ROWS
FETCH NEXT {recordsPerPage} ROWS ONLY
";

int count = connection.ExecuteScalar<int>(countSql);

DataTable results = connection.RetrieveData(sql);

return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(results),
RecordsPerPage = recordsPerPage,
TotalRecords = count,
NumberOfPages = (count + recordsPerPage - 1) / recordsPerPage
});
}
else
{
return Ok(new List<ChannelDetail>());
return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(new List<string>()), // just return an empty list
RecordsPerPage = recordsPerPage,
TotalRecords = 0,
NumberOfPages = 0
});
}
}
} catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using GSF.Data;
using GSF.Data.Model;
using GSF.Web.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using openXDA.Model;
using SystemCenter.Model;
Expand Down Expand Up @@ -94,6 +95,38 @@ record = record.Concat(new TableOperations<LineSegment>(connection).QueryRecords

}

[HttpPost, Route("{lineID:int}/LineSegments/{page:int}")]
public IHttpActionResult GetLineSegmentsForLinePaged([FromBody] PostData postData, [FromUri] int lineID, [FromUri] int page)
{
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
int recordsPerPage = PageSize ?? 50;

using (AdoDataConnection connection = new AdoDataConnection(Connection))
{
RecordRestriction restriction = new RecordRestriction(@"ID in (select ChildID from AssetRelationship where AssetRelationshipTypeID = (SELECT ID FROM AssetRelationshipType WHERE Name = 'Line-LineSegment') AND ParentID = {0})
OR ID in (select ParentID from AssetRelationship where AssetRelationshipTypeID = (SELECT ID FROM AssetRelationshipType WHERE Name = 'Line-LineSegment') AND ChildID = {0})", lineID);

TableOperations<LineSegment> tbl = new TableOperations<LineSegment>(connection);

int count = tbl.QueryRecordCount(restriction);

IEnumerable<LineSegment> records = tbl.QueryRecords(postData.OrderBy, postData.Ascending, page + 1, recordsPerPage, restriction);

return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(records),
RecordsPerPage = recordsPerPage,
TotalRecords = count,
NumberOfPages = (count + recordsPerPage - 1) / recordsPerPage
});
}
}
else
return Unauthorized();

}

public override IHttpActionResult Post([FromBody] JObject record)
{
if (PostRoles == string.Empty || User.IsInRole(PostRoles))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class OpenXDAMeterConfigurationController : ModelController<MeterConfigur
[HttpGet, Route("Meter/{meterID:int}/{page:int}")]
public IHttpActionResult GetMeterConfigurationsForMeter(int meterID, int page)
{
int recordsPerPage = 50;
int recordsPerPage = PageSize ?? 50;
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
Expand Down Expand Up @@ -93,7 +93,7 @@ ORDER BY
[HttpGet, Route("{meterConfigurationID:int}/FilesProcessed/{page:int}")]
public IHttpActionResult GetFilesProcessedForMeterConfigurations(int meterConfigurationID, int page)
{
int recordsPerPage = 50;
int recordsPerPage = PageSize ?? 50;
if (GetRoles == string.Empty || User.IsInRole(GetRoles))
{
using (AdoDataConnection connection = new AdoDataConnection(Connection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,15 @@ public IHttpActionResult UpdateMeterChannels([FromBody] JObject postData, int me
return Ok("Completed without errors");
}

[HttpGet, Route("{meterID:int}/Channels/{filter=All}")]
public IHttpActionResult GetMeterChannels(int meterID, string filter)
[HttpGet, Route("{meterID:int}/Channels/{page:int}/{filter=All}")]
public IHttpActionResult GetMeterChannels(int meterID, int page, string filter)
{
if (GetRoles != string.Empty && !User.IsInRole(GetRoles))
return Unauthorized();

const string ChannelQuery =
int recordsPerPage = PageSize ?? 50;

string ChannelQuery =
"SELECT " +
" Channel.ID, " +
" Meter.AssetKey AS Meter, " +
Expand All @@ -336,7 +338,8 @@ public IHttpActionResult GetMeterChannels(int meterID, string filter)
" MeasurementType ON Channel.MeasurementTypeID = MeasurementType.ID JOIN " +
" MeasurementCharacteristic ON Channel.MeasurementCharacteristicID = MeasurementCharacteristic.ID JOIN " +
" Phase ON Channel.PhaseID = Phase.ID " +
"WHERE MeterID = {0}";
"WHERE MeterID = {0} " +
$"ORDER BY Channel.Name ASC OFFSET {page * recordsPerPage} ROWS FETCH NEXT {recordsPerPage} ROWS ONLY";

const string SeriesQuery =
"SELECT " +
Expand All @@ -350,8 +353,12 @@ public IHttpActionResult GetMeterChannels(int meterID, string filter)
" Channel ON Series.ChannelID = Channel.ID " +
"WHERE Channel.MeterID = {0}";

string countQuery = "SELECT COUNT(Channel.ID) FROM Channel WHERE MeterID = {0}";

using (AdoDataConnection connection = ConnectionFactory())
{
int channelCount = connection.ExecuteScalar<int>(countQuery, meterID);

DataTable channelTable = connection.RetrieveData(ChannelQuery, meterID);
string channelJSON = JsonConvert.SerializeObject(channelTable);
JArray channelArray = JArray.Parse(channelJSON);
Expand Down Expand Up @@ -395,7 +402,13 @@ IEnumerable<JToken> FilterChannels()
}
}

return Ok(FilterChannels());
return Ok(new PagedResults()
{
Data = JsonConvert.SerializeObject(FilterChannels()),
TotalRecords = channelCount,
NumberOfPages = (channelCount + recordsPerPage - 1) / recordsPerPage,
RecordsPerPage = recordsPerPage
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public IHttpActionResult RecentFailures([FromBody] PostData postData, [FromUri]
if (!GetAuthCheck())
return Unauthorized();

int recordsPerPage = Take ?? 50;
int recordsPerPage = PageSize ?? 50;

List<object> param = new();

Expand Down
Loading