Skip to content

Commit ae7b0e6

Browse files
committed
#2238 download filtered data in package
1 parent 3be8b61 commit ae7b0e6

File tree

3 files changed

+119
-10
lines changed

3 files changed

+119
-10
lines changed

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Controllers/DataController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public ActionResult Show(long id, long version = 0)
110110
//get the researchobject (cuurently called dataset) to get the id of a metadata structure
111111
Dataset researcobject = this.GetUnitOfWork().GetReadOnlyRepository<Dataset>().Get(id);
112112

113+
114+
113115
if (researcobject != null)
114116
{
115117
long metadataStrutcureId = researcobject.MetadataStructure.Id;
@@ -173,6 +175,10 @@ public ActionResult ShowData(long id, int version = 0, bool asPartial = false, s
173175
ViewData["has_data"] = false;
174176
ViewData["data_aggreement"] = moduleSettings.GetValueByKey("data_aggreement");
175177
Session["Filter"] = null;
178+
// reset sessions
179+
Session["DataFilter"] = null;
180+
Session["DataOrderBy"] = null;
181+
Session["DataProjection"] = null;
176182

177183
Dataset researcobject = dm.GetDataset(id);
178184

@@ -864,6 +870,13 @@ public ActionResult _CustomPrimaryDataBinding(GridCommand command, string column
864870

865871
FilterExpression filter = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
866872
OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());
873+
ProjectionExpression projection = null;
874+
if(!string.IsNullOrEmpty(columns)) projection = TelerikGridHelper.Convert(columns.Replace("ID", "").Split(','));
875+
876+
Session["DataFilter"] = filter;
877+
Session["DataOrderBy"] = orderBy;
878+
Session["DataProjection"] = projection;
879+
867880

868881
table = dm.GetLatestDatasetVersionTuples(datasetId, filter, orderBy, null, "", command.Page - 1, command.PageSize);
869882
ViewData["gridTotal"] = dm.RowCount(datasetId, filter);
@@ -1423,6 +1436,7 @@ private DataTable getFilteredData(long datasetId)
14231436

14241437
ProjectionExpression projection = TelerikGridHelper.Convert(columns);
14251438

1439+
14261440
long count = datasetManager.RowCount(datasetId, filter);
14271441

14281442
DataTable table = datasetManager.GetLatestDatasetVersionTuples(datasetId, filter, orderBy, projection, "", 0, (int)count);

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/Controllers/ExportController.cs

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
using BExIS.Security.Entities.Subjects;
2020
using BExIS.Security.Entities.Versions;
2121
using BExIS.Security.Services.Utilities;
22+
using BExIS.UI.Helpers;
2223
using BExIS.Utils.Config;
2324
using BExIS.Utils.Extensions;
2425
using BExIS.Utils.Models;
26+
using BExIS.Utils.NH.Querying;
2527
using BExIS.Xml.Helpers;
2628
using Newtonsoft.Json;
2729
using System;
@@ -35,6 +37,8 @@
3537
using System.Web.Mvc;
3638
using System.Web.Routing;
3739
using System.Xml;
40+
using Telerik.Web.Mvc;
41+
using Vaelastrasz.Library.Models;
3842
using Vaiona.Logging;
3943
using Vaiona.Persistence.Api;
4044
using Vaiona.Utils.Cfg;
@@ -196,6 +200,9 @@ public ActionResult GenerateZip(long id, long versionid, string format)
196200
PublicationManager publicationManager = new PublicationManager();
197201
SubmissionManager publishingManager = new SubmissionManager();
198202

203+
bool isFilterInUse = filterInUse();
204+
string filteredFilePath = "";
205+
199206
string brokerName = "generic";
200207

201208
try
@@ -220,6 +227,8 @@ public ActionResult GenerateZip(long id, long versionid, string format)
220227

221228
#region primary data
222229

230+
231+
223232
// check the data sturcture type ...
224233
if (format != null && datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure && dm.GetDataTuplesCount(datasetVersion.Id) > 0)
225234
{
@@ -228,19 +237,28 @@ public ActionResult GenerateZip(long id, long versionid, string format)
228237
//check wheter title is empty or not
229238
title = String.IsNullOrEmpty(datasetVersion.Title) ? "no title available" : datasetVersion.Title;
230239

231-
switch (format)
240+
if (isFilterInUse)
241+
{
242+
DataTable filteredData = getFilteredData(id);
243+
filteredFilePath = odm.GenerateAsciiFile("temp", filteredData, title, format, datasetVersion.Dataset.DataStructure.Id, false);
244+
}
245+
else
232246
{
233-
case "application/xlsx":
234-
odm.GenerateExcelFile(id, datasetVersion.Id, false);
235-
break;
236247

237-
case "application/xlsm":
238-
odm.GenerateExcelFile(id, datasetVersion.Id, true);
239-
break;
248+
switch (format)
249+
{
250+
case "application/xlsx":
251+
odm.GenerateExcelFile(id, datasetVersion.Id, false);
252+
break;
240253

241-
default:
242-
odm.GenerateAsciiFile(id, datasetVersion.Id, format, false);
243-
break;
254+
case "application/xlsm":
255+
odm.GenerateExcelFile(id, datasetVersion.Id, true);
256+
break;
257+
258+
default:
259+
odm.GenerateAsciiFile(id, datasetVersion.Id, format, false);
260+
break;
261+
}
244262
}
245263
}
246264

@@ -272,6 +290,9 @@ public ActionResult GenerateZip(long id, long versionid, string format)
272290
#region zip file
273291

274292
string zipName = IOHelper.GetFileName(FileType.Bundle, id, datasetVersionNumber, dataStructureId, title); //publishingManager.GetZipFileName(id, datasetVersionNumber);
293+
// add suffix if filter is in use
294+
if (isFilterInUse) zipName += "_filtered";
295+
275296
string zipPath = Path.Combine(publishingManager.GetDirectoryPath(id, brokerName), zipName+".zip");
276297
FileHelper.CreateDicrectoriesIfNotExist(Path.GetDirectoryName(zipPath));
277298

@@ -316,6 +337,18 @@ public ActionResult GenerateZip(long id, long versionid, string format)
316337
}
317338
}
318339

340+
// if data was filtered add a text file with information about filtering
341+
if (isFilterInUse)
342+
{
343+
string path = Path.Combine(AppConfiguration.DataPath, filteredFilePath);
344+
string ext = Path.GetExtension(filteredFilePath).ToLower();
345+
string name = IOHelper.GetFileName(FileType.PrimaryData, id, datasetVersionNumber, dataStructureId)+"filtered"+ ext;
346+
347+
archive.AddFileToArchive(filteredFilePath, name);
348+
}
349+
350+
351+
319352
// xml schema
320353
string xsdPath = OutputMetadataManager.GetSchemaDirectoryPath(id);
321354
if (Directory.Exists(xsdPath))
@@ -332,6 +365,10 @@ public ActionResult GenerateZip(long id, long versionid, string format)
332365
datasetModel.DownloadInformation.DownloadSource = Request.Url.Host;
333366
datasetModel.DownloadInformation.DownloadedBy = getPartyNameOrDefault();
334367

368+
// set filter info
369+
if(isFilterInUse)
370+
datasetModel.DownloadInformation.DownloadedFilter = getFilterQuery();
371+
335372
if(datasetModel.DownloadInformation.DownloadedBy == "DEFAULT") datasetModel.DownloadInformation.DownloadedBy = "ANONYMOUS";
336373

337374
string manifest = JsonConvert.SerializeObject(datasetModel);
@@ -572,5 +609,62 @@ private string getPartyNameOrDefault()
572609
}
573610
return !string.IsNullOrWhiteSpace(userName) ? userName : "DEFAULT";
574611
}
612+
613+
private bool filterInUse()
614+
{
615+
if (Session["DataFilter"] != null || Session["DataOrderBy"] != null || Session["DataProjection"] != null )
616+
{
617+
return true;
618+
}
619+
620+
return false;
621+
}
622+
623+
private DataTable getFilteredData(long datasetId)
624+
{
625+
DatasetManager datasetManager = new DatasetManager();
626+
try
627+
{
628+
GridCommand command = null;
629+
FilterExpression filter = null;
630+
OrderByExpression orderBy = null;
631+
ProjectionExpression projection = null;
632+
string[] columns = null;
633+
634+
if (Session["DataFilter"] != null) filter = (FilterExpression)Session["DataFilter"];
635+
if (Session["DataOrderBy"] != null) orderBy = (OrderByExpression)Session["DataOrderBy"];
636+
if (Session["DataProjection"] != null) projection = (ProjectionExpression)Session["DataProjection"];
637+
638+
639+
long count = datasetManager.RowCount(datasetId, filter);
640+
641+
DataTable table = datasetManager.GetLatestDatasetVersionTuples(datasetId, filter, orderBy, projection, "", 0, (int)count);
642+
643+
if (projection == null) table.Strip();
644+
645+
return table;
646+
}
647+
finally
648+
{
649+
datasetManager.Dispose();
650+
}
651+
}
652+
653+
private string getFilterQuery()
654+
{
655+
FilterExpression filter = null;
656+
OrderByExpression orderBy = null;
657+
ProjectionExpression projection = null;
658+
string[] columns = null;
659+
660+
if (Session["DataFilter"] != null) filter = (FilterExpression)Session["DataFilter"];
661+
if (Session["DataOrderBy"] != null) orderBy = (OrderByExpression)Session["DataOrderBy"];
662+
if (Session["DataProjection"] != null) projection = (ProjectionExpression)Session["DataProjection"];
663+
664+
string query = filter?.ToSQL() + orderBy?.ToSQL() + projection?.ToSQL();
665+
666+
return query;
667+
}
668+
575669
}
576670
}

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/Models/Download/GeneralMetadataModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ public class DatasetDownloadInfoModel
5454
public string DownloadSource { get; set; }
5555
public string DownloadDate { get; set; }
5656
public string DownloadedBy { get; set; }
57+
public string DownloadedFilter { get; set; }
5758
}
5859
}

0 commit comments

Comments
 (0)