2020using BExIS . Utils . Extensions ;
2121using Vaiona . Web . Mvc . Modularity ;
2222using System . Web . Routing ;
23+ using Microsoft . AspNet . Identity ;
2324
2425namespace BExIS . Modules . Lui . UI . Controllers
2526{
@@ -47,9 +48,9 @@ public ActionResult Index()
4748
4849 //create model
4950 LUIQueryModel model = new LUIQueryModel ( ) ;
50- model . MissingComponentData = DataAccess . GetMissingComponentData ( ) ;
51+ model . MissingComponentData = DataAccess . GetMissingComponentData ( GetServerInformation ( ) ) ;
5152 model . NewComponentsSetDatasetId = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
52- model . NewComponentsSetDatasetVersion = DataAccess . GetDatasetInfo ( model . NewComponentsSetDatasetId ) . Version ;
53+ model . NewComponentsSetDatasetVersion = DataAccess . GetDatasetInfo ( model . NewComponentsSetDatasetId , GetServerInformation ( ) ) . Version ;
5354 return View ( "Index" , model ) ;
5455
5556 }
@@ -69,7 +70,7 @@ public ActionResult ShowPrimaryData(long datasetID)
6970 Session [ "LUICalModel" ] = lUIQueryModel ;
7071
7172 DataModel model = new DataModel ( ) ;
72- model . Data = DataAccess . GetComponentData ( datasetID . ToString ( ) ) ;
73+ model . Data = DataAccess . GetComponentData ( datasetID . ToString ( ) , GetServerInformation ( ) ) ;
7374
7475 return PartialView ( "_data" , model ) ;
7576 }
@@ -105,7 +106,19 @@ public ActionResult CalculateLUI(LUIQueryModel model)
105106 Session [ "DataStructureId" ] = selectedDataStructureId ;
106107
107108 // do the calucaltion
108- var results = CalculateLui . DoCalc ( model ) ;
109+ // source data
110+ string dsId = "" ;
111+ switch ( model . ComponentsSet . SelectedValue )
112+ {
113+ case "old components set" :
114+ dsId = Models . Settings . get ( "lui:datasetOldComponentsSet" ) . ToString ( ) ;
115+ break ;
116+ case "new components set" :
117+ dsId = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
118+ break ;
119+ }
120+ DataTable dt_sourceData = DataAccess . GetComponentData ( dsId , GetServerInformation ( ) ) ;
121+ var results = CalculateLui . DoCalc ( model , dt_sourceData ) ;
109122
110123 DataModel dataModel = new DataModel ( ) ;
111124 dataModel . Data = results ;
@@ -142,7 +155,7 @@ public ActionResult PrepareDownloadFile(string mimeType)
142155 LUIQueryModel model = ( LUIQueryModel ) Session [ "LUICalModel" ] ;
143156
144157 if ( model . RawVsCalc . SelectedValue == "unstandardized" )
145- downloadData = DataAccess . GetComponentData ( model . DownloadDatasetId ) ;
158+ downloadData = DataAccess . GetComponentData ( model . DownloadDatasetId , GetServerInformation ( ) ) ;
146159 else
147160 downloadData = Session [ SESSION_TABLE ] as DataTable ;
148161
@@ -177,7 +190,7 @@ public ActionResult PrepareDownloadFile(string mimeType)
177190 //XmlDocument xmlDocument = DataAccess.GetMetadata(model.DownloadDatasetId);
178191
179192 //string htmlPage = PartialView("SimpleMetadata", xmlDocument).RenderToString();
180- DatasetObject datasetObject = DataAccess . GetDatasetInfo ( model . DownloadDatasetId ) ;
193+ DatasetObject datasetObject = DataAccess . GetDatasetInfo ( model . DownloadDatasetId , GetServerInformation ( ) ) ;
181194 var view = this . Render ( "DCM" , "Form" , "LoadMetadataOfflineVersion" , new RouteValueDictionary ( )
182195 {
183196 { "entityId" , long . Parse ( model . DownloadDatasetId ) } ,
@@ -192,11 +205,11 @@ public ActionResult PrepareDownloadFile(string mimeType)
192205 string pathHtml = downloadManager . GenerateHtmlFile ( view . ToHtmlString ( ) , model . DownloadDatasetId + "_metadata" ) ;
193206
194207 //get missing data when relavent
195- List < MissingComponentData > missingComponentData = DataAccess . GetMissingComponentData ( ) ;
208+ List < MissingComponentData > missingComponentData = DataAccess . GetMissingComponentData ( GetServerInformation ( ) ) ;
196209 string pathMissingData = "" ;
197210 if ( missingComponentData . Count > 0 )
198211 {
199- string version = DataAccess . GetDatasetInfo ( model . DownloadDatasetId ) . Version ;
212+ string version = DataAccess . GetDatasetInfo ( model . DownloadDatasetId , GetServerInformation ( ) ) . Version ;
200213 string filenameMissingdata = model . DownloadDatasetId + "_" + "Version_" + version + "_" + "MissingComponentData" ;
201214 pathMissingData = downloadManager . GernateMissingDataFile ( missingComponentData , filenameMissingdata ) ;
202215 }
@@ -269,7 +282,7 @@ public ActionResult DownloadFile(string mimeType)
269282 else
270283 datasetId = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
271284
272- string version = DataAccess . GetDatasetInfo ( datasetId ) . Version ;
285+ string version = DataAccess . GetDatasetInfo ( datasetId , GetServerInformation ( ) ) . Version ;
273286
274287 string text = "LUI Calculation file <b>\" " + Path . GetFileName ( pathData ) + "\" </b> with id <b>(" + datasetId + ")</b> version <b>(" + version + ")</b> was downloaded by <b>" + user + "</b>" ;
275288 es . Send ( "LUI data was downloaded (Id: " + datasetId + ", Version: " + version + ")" , text , "bexis-sys@listserv.uni-jena.de" ) ;
@@ -300,15 +313,15 @@ private bool checkPreconditions()
300313 // check for LUI new dataset
301314 bool exists = false ;
302315 string luiIdNew = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
303- var dataNew = DataAccess . GetComponentData ( luiIdNew ) ;
316+ var dataNew = DataAccess . GetComponentData ( luiIdNew , GetServerInformation ( ) ) ;
304317 if ( dataNew . Rows . Count == 0 )
305318 return exists == false ;
306319
307320 string dsdId = Models . Settings . get ( "lui:datastructureNewComponentsSet" ) . ToString ( ) ;
308321
309322 // check for LUI old dataset
310323 string luiIdOld = Models . Settings . get ( "lui:datasetOldComponentsSet" ) . ToString ( ) ;
311- var dataOld = DataAccess . GetComponentData ( luiIdOld ) ;
324+ var dataOld = DataAccess . GetComponentData ( luiIdOld , GetServerInformation ( ) ) ;
312325 if ( dataOld . Rows . Count == 0 )
313326 return exists == false ;
314327
@@ -317,6 +330,45 @@ private bool checkPreconditions()
317330 // if we came that far, all conditions are met
318331 return true ;
319332 }
333+
334+ /// <summary>
335+ /// Get current server und user information
336+ /// </summary>
337+ /// <returns></returns>
338+ public ServerInformation GetServerInformation ( )
339+ {
340+ //string filePath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("LUI"), "Credentials.json");
341+ //string text = System.IO.File.ReadAllText(filePath);
342+ ServerInformation serverInformation = new ServerInformation ( ) ;
343+ var uri = System . Web . HttpContext . Current . Request . Url ;
344+ serverInformation . ServerName = uri . GetLeftPart ( UriPartial . Authority ) ;
345+ serverInformation . Token = GetUserToken ( ) ;
346+
347+
348+ return serverInformation ;
349+ }
350+ private string GetUserToken ( )
351+ {
352+ var identityUserService = new IdentityUserService ( ) ;
353+ var userManager = new UserManager ( ) ;
354+
355+ try
356+ {
357+ long userId = 0 ;
358+ long . TryParse ( this . User . Identity . GetUserId ( ) , out userId ) ;
359+
360+ var user = identityUserService . FindById ( userId ) ;
361+
362+ user = identityUserService . FindById ( userId ) ;
363+ var token = userManager . GetTokenAsync ( user ) . Result ;
364+ return token ;
365+ }
366+ finally
367+ {
368+ identityUserService . Dispose ( ) ;
369+ userManager . Dispose ( ) ;
370+ }
371+ }
320372 }
321373
322374}
0 commit comments