19
19
import org .cgiar .ccafs .marlo .config .APConstants ;
20
20
import org .cgiar .ccafs .marlo .data .manager .CrpManager ;
21
21
import org .cgiar .ccafs .marlo .data .manager .CrpProgramManager ;
22
+ import org .cgiar .ccafs .marlo .data .manager .DeliverableFundingSourceManager ;
22
23
import org .cgiar .ccafs .marlo .data .manager .ProjectManager ;
23
24
import org .cgiar .ccafs .marlo .data .model .Crp ;
25
+ import org .cgiar .ccafs .marlo .data .model .DeliverableFundingSource ;
24
26
import org .cgiar .ccafs .marlo .data .model .FundingSource ;
25
27
import org .cgiar .ccafs .marlo .data .model .FundingSourceBudget ;
26
28
import org .cgiar .ccafs .marlo .data .model .FundingSourceInstitution ;
29
31
import org .cgiar .ccafs .marlo .data .model .ProjectBudget ;
30
32
import org .cgiar .ccafs .marlo .data .model .ProjectClusterActivity ;
31
33
import org .cgiar .ccafs .marlo .data .model .ProjectFocus ;
34
+ import org .cgiar .ccafs .marlo .data .model .ProjectStatusEnum ;
32
35
import org .cgiar .ccafs .marlo .utils .APConfig ;
33
36
34
37
import java .io .ByteArrayInputStream ;
@@ -82,6 +85,7 @@ public class FundingSourcesSummaryAction extends BaseAction implements Summary {
82
85
private CrpManager crpManager ;
83
86
private CrpProgramManager programManager ;
84
87
private ProjectManager projectManager ;
88
+ private DeliverableFundingSourceManager deliverableFundingSourceManager ;
85
89
86
90
// XLSX bytes
87
91
private byte [] bytesXLSX ;
@@ -91,11 +95,12 @@ public class FundingSourcesSummaryAction extends BaseAction implements Summary {
91
95
92
96
@ Inject
93
97
public FundingSourcesSummaryAction (APConfig config , CrpManager crpManager , CrpProgramManager programManager ,
94
- ProjectManager projectManager ) {
98
+ ProjectManager projectManager , DeliverableFundingSourceManager deliverableFundingSourceManager ) {
95
99
super (config );
96
100
this .crpManager = crpManager ;
97
101
this .programManager = programManager ;
98
102
this .projectManager = projectManager ;
103
+ this .deliverableFundingSourceManager = deliverableFundingSourceManager ;
99
104
}
100
105
101
106
@ Override
@@ -287,9 +292,9 @@ public String getFundingSourceFileURL() {
287
292
private TypedTableModel getFundingSourcesProjectsTableModel () {
288
293
TypedTableModel model = new TypedTableModel (
289
294
new String [] {"fs_title" , "fs_id" , "finance_code" , "lead_partner" , "fs_window" , "project_id" , "total_budget" ,
290
- "flagships" , "coas" },
295
+ "flagships" , "coas" , "deliverables" },
291
296
new Class [] {String .class , Long .class , String .class , String .class , String .class , String .class , Double .class ,
292
- String .class , String .class },
297
+ String .class , String .class , String . class },
293
298
0 );
294
299
295
300
for (FundingSource fundingSource : loggedCrp .getFundingSources ().stream ()
@@ -304,12 +309,16 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
304
309
305
310
306
311
for (ProjectBudget projectBudget : fundingSource .getProjectBudgets ().stream ()
307
- .filter (pb -> pb .isActive () && pb .getYear () == year && pb .getProject () != null ).collect (Collectors .toList ())) {
312
+ .filter (pb -> pb .isActive () && pb .getYear () == year && pb .getProject () != null && pb .getProject ().isActive ()
313
+ && pb .getProject ().getStatus () != null
314
+ && pb .getProject ().getStatus ().intValue () == Integer .parseInt (ProjectStatusEnum .Ongoing .getStatusId ()))
315
+ .collect (Collectors .toList ())) {
308
316
String lead_partner = "" ;
309
317
String project_id = "" ;
310
318
Double total_budget = 0.0 ;
311
319
String flagships = null ;
312
320
String coas = null ;
321
+ String deliverables = "" ;
313
322
314
323
project_id = projectBudget .getProject ().getId ().toString ();
315
324
if (project_id != null && !project_id .isEmpty ()) {
@@ -325,8 +334,28 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
325
334
flagships +=
326
335
"\n " + programManager .getCrpProgramById (projectFocuses .getCrpProgram ().getId ()).getAcronym ();
327
336
}
328
- }
337
+ // get deliverable funding sources
338
+ Long projectID = Long .parseLong (project_id );
339
+
340
+ for (DeliverableFundingSource deliverableFundingSource : this .deliverableFundingSourceManager .findAll ()
341
+ .stream ()
342
+ .filter (df -> df .getFundingSource ().getId ().longValue () == fundingSource .getId ().longValue ()
343
+ && df .isActive () && df .getDeliverable () != null && df .getDeliverable ().isActive ()
344
+ && df .getDeliverable ().getProject () != null
345
+ && df .getDeliverable ().getProject ().getId ().longValue () == projectID .longValue ())
346
+ .sorted ((df1 , df2 ) -> Long .compare (df1 .getDeliverable ().getId (), df2 .getDeliverable ().getId ()))
347
+ .collect (Collectors .toList ())) {
348
+ if (deliverables .length () == 0 ) {
349
+ deliverables = "D" + deliverableFundingSource .getDeliverable ().getId ();
350
+ } else {
351
+ deliverables += ", D" + deliverableFundingSource .getDeliverable ().getId ();
352
+ }
353
+ }
329
354
355
+ }
356
+ if (deliverables .isEmpty ()) {
357
+ deliverables = null ;
358
+ }
330
359
// get CoAs related to the project sorted by acronym
331
360
if (projectBudget .getProject ().getProjectClusterActivities () != null ) {
332
361
for (ProjectClusterActivity projectClusterActivity : projectBudget .getProject ()
@@ -348,7 +377,7 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
348
377
total_budget = projectBudget .getAmount ();
349
378
350
379
model .addRow (new Object [] {fs_title , fs_id , finance_code , lead_partner , fs_window , project_id , total_budget ,
351
- flagships , coas });
380
+ flagships , coas , deliverables });
352
381
}
353
382
354
383
}
@@ -359,10 +388,10 @@ private TypedTableModel getFundingSourcesTableModel() {
359
388
TypedTableModel model = new TypedTableModel (
360
389
new String [] {"fs_title" , "fs_id" , "finance_code" , "lead_partner" , "fs_window" , "project_id" , "total_budget" ,
361
390
"summary" , "start_date" , "end_date" , "contract" , "status" , "pi_name" , "pi_email" , "donor" ,
362
- "total_budget_projects" , "contract_name" , "flagships" , "coas" },
391
+ "total_budget_projects" , "contract_name" , "flagships" , "coas" , "deliverables" },
363
392
new Class [] {String .class , Long .class , String .class , String .class , String .class , String .class , Double .class ,
364
393
String .class , String .class , String .class , String .class , String .class , String .class , String .class , String .class ,
365
- Double .class , String .class , String .class , String .class },
394
+ Double .class , String .class , String .class , String .class , String . class },
366
395
0 );
367
396
SimpleDateFormat formatter = new SimpleDateFormat ("MMM yyyy" );
368
397
@@ -497,9 +526,26 @@ private TypedTableModel getFundingSourcesTableModel() {
497
526
total_budget_projects += projectBudget .getAmount ();
498
527
}
499
528
529
+ // get deliverable funding sources
530
+ String deliverables = "" ;
531
+ for (DeliverableFundingSource deliverableFundingSource : this .deliverableFundingSourceManager .findAll ().stream ()
532
+ .filter (df -> df .getFundingSource ().getId ().longValue () == fundingSource .getId ().longValue () && df .isActive ()
533
+ && df .getDeliverable () != null && df .getDeliverable ().isActive () && df .getDeliverable ().getProject () != null
534
+ && df .getDeliverable ().getProject ().isActive ())
535
+ .sorted ((df1 , df2 ) -> Long .compare (df1 .getDeliverable ().getId (), df2 .getDeliverable ().getId ()))
536
+ .collect (Collectors .toList ())) {
537
+ if (deliverables .length () == 0 ) {
538
+ deliverables = "D" + deliverableFundingSource .getDeliverable ().getId ();
539
+ } else {
540
+ deliverables += ", D" + deliverableFundingSource .getDeliverable ().getId ();
541
+ }
542
+ }
543
+ if (deliverables .isEmpty ()) {
544
+ deliverables = null ;
545
+ }
500
546
model .addRow (new Object [] {fs_title , fs_id , finance_code , lead_partner , fs_window , project_id , total_budget ,
501
547
summary , start_date , end_date , contract , status , pi_name , pi_email , donor , total_budget_projects , contract_name ,
502
- flagships , coas });
548
+ flagships , coas , deliverables });
503
549
}
504
550
return model ;
505
551
}
0 commit comments