Skip to content

Commit 4f5eb6a

Browse files
authored
Merge pull request #789 from socialappslab/feature/783
Feature/783
2 parents 6a8de9b + c3b0254 commit 4f5eb6a

File tree

1 file changed

+58
-61
lines changed

1 file changed

+58
-61
lines changed

app/delegates/NotificationsDelegate.java

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
333333
String resourceText = "";
334334
Date resourceDate = new Date();
335335
String associatedUser = "";
336-
336+
Long resourceId = null;
337+
Map<String, Long> urls = new HashMap<>();
337338
Boolean originIsResourceSpace = false;
338339
if (origin instanceof ResourceSpace) {
339340
originIsResourceSpace = true;
@@ -392,10 +393,14 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
392393
resourceText = ((Contribution) resource).getText();
393394
resourceDate = resource.getCreation();
394395
resourceType = ((Contribution) resource).getType().toString();
396+
resourceId = ((Contribution) resource).getContributionId();
395397
if (resourceType.equals("BRAINSTORMING")) resourceType = "IDEA";
396398
title = "[AppCivist] New " + resourceType + " in " + originName;
397399
int numAuthors = ((Contribution) resource).getAuthors().size();
398400
associatedUser = ((Contribution) resource).getAuthors().get(0).getName() + (numAuthors > 1 ? " et. al." : "");
401+
Contribution contribution = (Contribution) resource;
402+
setContributionUrl(contribution, urls);
403+
399404
break;
400405
case UPDATED_CONTRIBUTION_IDEA:
401406
case UPDATED_CONTRIBUTION_PROPOSAL:
@@ -408,10 +413,12 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
408413
resourceText = ((Contribution) resource).getText();
409414
resourceDate = resource.getLastUpdate();
410415
resourceType = ((Contribution) resource).getType().toString();
416+
resourceId = ((Contribution) resource).getContributionId();
411417
if (resourceType.equals("BRAINSTORMING")) resourceType = "IDEA";
412418
title = "[AppCivist] Updated " + resourceType + " in " + originName;
413419
numAuthors = ((Contribution) resource).getAuthors().size();
414420
associatedUser = ((Contribution) resource).getAuthors().get(0).getName() + (numAuthors > 1 ? " et. al." : "");
421+
setContributionUrl((Contribution) resource, urls);
415422
break;
416423
// case NEW_CONTRIBUTION_FEEDBACK:
417424
// case UPDATED_CONTRIBUTION_FEEDBACK:
@@ -430,10 +437,12 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
430437
resourceUuid = ((Campaign) resource).getUuid();
431438
resourceTitle = ((Campaign) resource).getTitle();
432439
resourceText = ((Campaign) resource).getGoal();
440+
resourceId = ((Campaign) resource).getCampaignId();
433441
resourceDate = resource.getCreation();
434442
resourceType = AppcivistResourceTypes.CAMPAIGN.toString();
435443
title = "[AppCivist] New " + resourceType + " in " + originName;
436444
Logger.info("Title: " + title);
445+
setCampaignUrl(((Campaign) resource).getCampaignId(), urls);
437446
// TODO: add creator to campaign associatedUser = ((Campaign) resource).getCreator().getName();
438447
break;
439448
case NEW_CONTRIBUTION_FEEDBACK:
@@ -442,24 +451,29 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
442451
resourceUuid = ((Campaign) resource).getUuid();
443452
resourceTitle = ((Campaign) resource).getTitle();
444453
resourceText = ((Campaign) resource).getGoal();
454+
resourceId = ((Campaign) resource).getCampaignId();
445455
resourceDate = resource.getLastUpdate();
446456
resourceType = AppcivistResourceTypes.CAMPAIGN.toString();
447457
title = "[AppCivist] Updated " + resourceType + " in " + originName;
458+
setCampaignUrl(((Campaign) resource).getCampaignId(), urls);
448459
// TODO: add creator to campaign associatedUser = ((Campaign) resource).getCreator().getName();
449460
break;
450461
case NEW_WORKING_GROUP:
451462
resourceUuid = ((WorkingGroup) resource).getUuid();
452463
resourceTitle = ((WorkingGroup) resource).getName();
453464
resourceText = ((WorkingGroup) resource).getText();
465+
resourceId = ((WorkingGroup) resource).getGroupId();
454466
resourceDate = resource.getCreation();
455467
resourceType = AppcivistResourceTypes.WORKING_GROUP.toString();
456468
title = "[AppCivist] New " + resourceType + " in " + originName;
457469
associatedUser = ((WorkingGroup) resource).getCreator().getName();
470+
setWorkingGroupUrl(resourceId, urls);
458471
break;
459472
case UPDATED_WORKING_GROUP:
460473
resourceUuid = ((WorkingGroup) resource).getUuid();
461474
resourceTitle = ((WorkingGroup) resource).getName();
462475
resourceText = ((WorkingGroup) resource).getText();
476+
resourceId = ((WorkingGroup) resource).getGroupId();
463477
resourceDate = resource.getLastUpdate();
464478
resourceType = AppcivistResourceTypes.WORKING_GROUP.toString();
465479
title = "[AppCivist] Updated " + resourceType + " in " + originName;
@@ -468,22 +482,9 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
468482
} else {
469483
associatedUser = "";
470484
}
485+
setWorkingGroupUrl(resourceId, urls);
471486
break;
472487
case NEW_VOTING_BALLOT:
473-
Logger.info("NEW_VOTING_BALLOT");
474-
WorkingGroup wg = (WorkingGroup) resource;
475-
//TODO: HOW TO KNOW WHAT BALLOT IS THE LAST
476-
Ballot lastBallot = wg.getBallots().get(wg.getBallots().size() - 1);
477-
resourceUuid = lastBallot.getUuid();
478-
resourceTitle = lastBallot.getDecisionType();
479-
resourceText = lastBallot.getNotes();
480-
resourceDate = lastBallot.getCreatedAt();
481-
resourceType = AppcivistResourceTypes.BALLOT.toString();
482-
title = "[AppCivist] Updated " + resourceType + " in " + originName;
483-
//TODO: how to get the associatedUser
484-
associatedUser = "";
485-
Logger.info("DATOS NOTIFICACION( " + originUUID + ", " + originType + ", " + originName + ", " + eventName + ", " + title + ", " + text + ", " + resourceUuid + ", " + resourceTitle + ", " + resourceText + ", " + resourceDate + ", " + resourceType + ", " + associatedUser + ")");
486-
break;
487488
case UPDATED_VOTING_BALLOT:
488489
// // TODO: how to describe updated ballots that are not descendants of AppCivistBaseModel
489490
WorkingGroup uwg = (WorkingGroup) resource;
@@ -494,6 +495,7 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
494495
resourceText = ulastBallot.getNotes();
495496
resourceDate = ulastBallot.getCreatedAt();
496497
resourceType = AppcivistResourceTypes.BALLOT.toString();
498+
resourceId = ulastBallot.getId();
497499
title = "[AppCivist] Updated " + resourceType + " in " + originName;
498500
//TODO: how to get the associatedUser
499501
associatedUser = "";
@@ -503,26 +505,20 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
503505
case UPDATED_MILESTONE:
504506
case MILESTONE_PASSED:
505507
case MILESTONE_UPCOMING:
506-
resourceUuid = ((ComponentMilestone) resource).getUuid();
507-
resourceTitle = ((ComponentMilestone) resource).getTitle();
508-
resourceText = ((ComponentMilestone) resource).getDescription();
509-
resourceDate = ((ComponentMilestone) resource).getDate();
510-
resourceType = "MILESTONE";
511-
// TODO: add creator to milestones associatedUser = ((ComponentMilestone) resource).getCreator().getName();
512-
break;
513508
case MILESTONE_UPCOMING_IN_A_WEEK:
514-
resourceUuid = ((ComponentMilestone) resource).getUuid();
515-
resourceTitle = ((ComponentMilestone) resource).getTitle();
516-
resourceText = ((ComponentMilestone) resource).getDescription();
517-
resourceDate = ((ComponentMilestone) resource).getDate();
518-
resourceType = "MILESTONE";
519-
break;
520509
case MILESTONE_UPCOMING_IN_A_DAY:
510+
// TODO: add creator to milestones associatedUser = ((ComponentMilestone) resource).getCreator().getName();
521511
resourceUuid = ((ComponentMilestone) resource).getUuid();
522512
resourceTitle = ((ComponentMilestone) resource).getTitle();
523513
resourceText = ((ComponentMilestone) resource).getDescription();
524514
resourceDate = ((ComponentMilestone) resource).getDate();
515+
resourceId = ((ComponentMilestone) resource).getComponentMilestoneId();
525516
resourceType = "MILESTONE";
517+
try {
518+
setCampaignUrl(((ComponentMilestone) resource).getContainingSpaces().get(0).getCampaign().getCampaignId(), urls);
519+
} catch (Exception e) {
520+
Logger.error("Error setting milestone campaign id: none campaign foung");
521+
}
526522
break;
527523
case MEMBER_JOINED:
528524
break;
@@ -531,72 +527,71 @@ public static Result signalNotification(ResourceSpaceTypes originType, Notificat
531527
case UPDATED_CONTRIBUTION_HISTORY:
532528
break;
533529
case BALLOT_UPCOMING_IN_A_DAY:
534-
resourceUuid = ((Campaign) resource).getUuid();
535-
resourceTitle = ((Campaign) resource).getTitle();
536-
resourceText = ((Campaign) resource).getGoal();
537-
resourceDate = resource.getLastUpdate();
538-
resourceType = AppcivistResourceTypes.BALLOT.toString();
539-
break;
540530
case BALLOT_UPCOMING_IN_A_WEEK:
541-
resourceUuid = ((Campaign) resource).getUuid();
542-
resourceTitle = ((Campaign) resource).getTitle();
543-
resourceText = ((Campaign) resource).getGoal();
544-
resourceDate = resource.getLastUpdate();
545-
resourceType = AppcivistResourceTypes.BALLOT.toString();
546-
break;
547531
case BALLOT_UPCOMING_IN_A_MONTH:
548-
resourceUuid = ((Campaign) resource).getUuid();
549-
resourceTitle = ((Campaign) resource).getTitle();
550-
resourceText = ((Campaign) resource).getGoal();
551-
resourceDate = resource.getLastUpdate();
552-
resourceType = AppcivistResourceTypes.BALLOT.toString();
553-
break;
554532
case BALLOT_ENDING_IN_A_DAY:
555-
resourceUuid = ((Campaign) resource).getUuid();
556-
resourceTitle = ((Campaign) resource).getTitle();
557-
resourceText = ((Campaign) resource).getGoal();
558-
resourceDate = resource.getLastUpdate();
559-
resourceType = AppcivistResourceTypes.BALLOT.toString();
560-
break;
561533
case BALLOT_ENDING_IN_A_WEEK:
562-
resourceUuid = ((Campaign) resource).getUuid();
563-
resourceTitle = ((Campaign) resource).getTitle();
564-
resourceText = ((Campaign) resource).getGoal();
565-
resourceDate = resource.getLastUpdate();
566-
resourceType = AppcivistResourceTypes.BALLOT.toString();
567-
break;
568534
case BALLOT_ENDING_IN_A_MONTH:
569535
resourceUuid = ((Campaign) resource).getUuid();
570536
resourceTitle = ((Campaign) resource).getTitle();
571537
resourceText = ((Campaign) resource).getGoal();
538+
resourceId = ((Campaign) resource).getCampaignId();
572539
resourceDate = resource.getLastUpdate();
573540
resourceType = AppcivistResourceTypes.BALLOT.toString();
541+
setCampaignUrl(resourceId, urls);
574542
break;
575543
case NEWSLETTER:
576544
switch (originType) {
577545
case CAMPAIGN:
578546
resourceUuid = ((Campaign) resource).getUuid();
579547
resourceTitle = ((Campaign) resource).getTitle();
580548
resourceText = ((Campaign) resource).getGoal();
549+
resourceId = ((Campaign) resource).getCampaignId();
581550
resourceDate = resource.getLastUpdate();
582551
resourceType = AppcivistResourceTypes.CAMPAIGN.toString();
583552
title = "[AppCivist] New Newsletter for " + resourceType;
553+
setCampaignUrl(resourceId, urls);
584554
break;
585555
case WORKING_GROUP:
586556
resourceUuid = ((WorkingGroup) resource).getUuid();
587557
resourceTitle = ((WorkingGroup) resource).getName();
588558
resourceText = ((WorkingGroup) resource).getText();
559+
resourceId = ((WorkingGroup) resource).getGroupId();
589560
resourceDate = resource.getCreation();
590561
resourceType = AppcivistResourceTypes.WORKING_GROUP.toString();
591562
title = "[AppCivist] New Newsletter for " + resourceType;
563+
setWorkingGroupUrl(resourceId, urls);
592564
break;
593565
}
594566
default:
595567
break;
596568
}
597-
Logger.info("Sending signalNotification( " + originUUID + ", " + originType + ", " + originName + ", " + eventName + ", " + title + ", " + text + ", " + resourceUuid + ", " + resourceTitle + ", " + resourceText + ", " + resourceDate + ", " + resourceType + ", " + associatedUser + ")");
598-
return signalNotification(originUUID, originType, originName, eventName, title, text, resourceUuid, resourceTitle, resourceText, resourceDate, resourceType, associatedUser, subscriptionType, userParam);
569+
Logger.info("Sending signalNotification( " + originUUID + ", " + originType + ", " + originName + ", " + eventName + ", " + title + ", " + text + ", " + resourceUuid + ", " + resourceTitle + ", " + resourceText + ", " + resourceDate + ", " + resourceType + ", " + associatedUser + ","+resourceId+")");
570+
return signalNotification(originUUID, originType, originName, eventName, title, text, resourceUuid, resourceTitle, resourceText, resourceDate, resourceType, associatedUser, subscriptionType, userParam, resourceId, urls);
571+
572+
}
599573

574+
private static void setContributionUrl(Contribution contribution, Map<String, Long> urls) {
575+
urls.put("contributionId", contribution.getContributionId());
576+
if (!contribution.getWorkingGroups().isEmpty()) {
577+
setWorkingGroupUrl(contribution.getWorkingGroups().get(0).getGroupId(), urls);
578+
}
579+
}
580+
581+
private static void setWorkingGroupUrl(Long workingGroupId, Map<String, Long> urls) {
582+
WorkingGroup workingGroup = WorkingGroup.read(workingGroupId);
583+
urls.put("workingGroupId", workingGroupId);
584+
if(!workingGroup.getCampaigns().isEmpty()) {
585+
setCampaignUrl(workingGroup.getCampaigns().get(0), urls);
586+
}
587+
}
588+
589+
private static void setCampaignUrl(Long campaignId, Map<String, Long> urls) {
590+
urls.put("campaignId", campaignId);
591+
Campaign campaign = Campaign.find.byId(campaignId);
592+
if(!campaign.getAssemblies().isEmpty()){
593+
urls.put("assemblyId", campaign.getAssemblies().get(0));
594+
}
600595
}
601596

602597
// TODO: signalNotification for non AppCivistBaseModel Resources: VotingBallot
@@ -611,7 +606,8 @@ public static Result signalNotification(UUID origin,
611606
String resourceType,
612607
String associatedUser,
613608
SubscriptionTypes subscriptionType,
614-
User userParam) {
609+
User userParam,
610+
Long resourceID, Map<String, Long> urls) {
615611
// 1. Prepare the notification event data
616612
NotificationEventSignal notificationEvent = new NotificationEventSignal();
617613
notificationEvent.setSpaceType(originType);
@@ -634,6 +630,7 @@ public static Result signalNotification(UUID origin,
634630
data.put("notificationDate", notificationDate);
635631
data.put("associatedUser", associatedUser);
636632
data.put("signaled", false);
633+
data.put("originIds", urls);
637634
try {
638635
if (subscriptionType.equals(SubscriptionTypes.NEWSLETTER)) {
639636

0 commit comments

Comments
 (0)