Skip to content

Commit

Permalink
Merge branch 'aiccra-dev-A2-392-IPI-2.3' into aiccra-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed May 9, 2024
2 parents b655af3 + 17df276 commit 69b4d63
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8804,6 +8804,14 @@ public boolean validateCenterTopic(CrpProgram program, String sectionName) {
return true;
}

public boolean validateEmailNotification() {
GlobalUnit globalUnit = this.getCurrentCrp();
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}

public boolean validatePolicy(long policyID) {
SectionStatus sectionStatus =
this.sectionStatusManager.getSectionStatusByProjectPolicy(policyID, this.getCurrentCycle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,4 @@ public void validate() {
}
}

public boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,5 @@ public void setLoggedCrp(GlobalUnit loggedCrp) {
this.loggedCrp = loggedCrp;
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,4 @@ public void validate() {
}
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,4 @@ private void siteIntegrationPreviusData() {
}
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1035,12 +1035,4 @@ public void validate() {
}
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,4 @@ public void setTargetUnitName(String targetUnitName) {
this.targetUnitName = targetUnitName;
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,4 @@ public void setResults(ArrayList<Map<String, String>> results) {
}


private boolean validateEmailNotification() {

return globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,4 @@ public void setSucess(Map<String, Object> sucess) {
}


private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
import org.cgiar.ccafs.marlo.security.Permission;
import org.cgiar.ccafs.marlo.utils.APConfig;
import org.cgiar.ccafs.marlo.utils.AutoSaveReader;
import org.cgiar.ccafs.marlo.utils.SendMailS;
import org.cgiar.ccafs.marlo.utils.doi.DOIService;
import org.cgiar.ccafs.marlo.validation.projects.DeliverableValidator;

Expand Down Expand Up @@ -323,6 +324,8 @@ public class DeliverableAction extends BaseAction {
private Integer acceptationPercentage;
private List<ProjectOutcome> projectOutcomes;
private boolean existCurrentCluster;
private final SendMailS sendMail;
private int previousStatus;

@Inject
public DeliverableAction(APConfig config, DeliverableTypeManager deliverableTypeManager,
Expand Down Expand Up @@ -366,7 +369,8 @@ public DeliverableAction(APConfig config, DeliverableTypeManager deliverableType
DeliverableTraineesIndicatorManager deliverableTraineesIndicatorManager,
ShfrmPriorityActionManager shfrmPriorityActionManager, ShfrmSubActionManager shfrmSubActionManager,
DeliverableShfrmPriorityActionManager deliverableShfrmPriorityActionManager,
DeliverableShfrmSubActionManager deliverableShfrmSubActionManager, SoilIndicatorManager soilIndicatorManager) {
DeliverableShfrmSubActionManager deliverableShfrmSubActionManager, SoilIndicatorManager soilIndicatorManager,
SendMailS sendMail) {
super(config);
this.activityManager = activityManager;
this.deliverableManager = deliverableManager;
Expand Down Expand Up @@ -433,6 +437,7 @@ public DeliverableAction(APConfig config, DeliverableTypeManager deliverableType
this.deliverableShfrmPriorityActionManager = deliverableShfrmPriorityActionManager;
this.deliverableShfrmSubActionManager = deliverableShfrmSubActionManager;
this.soilIndicatorManager = soilIndicatorManager;
this.sendMail = sendMail;
}

/**
Expand Down Expand Up @@ -1604,6 +1609,12 @@ public void prepare() throws Exception {
if (deliverable.getDeliverableInfo(this.getActualPhase()) == null) {
deliverable.setDeliverableInfo(new DeliverableInfo());
}

// Status prev
if (deliverable.getDeliverableInfo(this.getActualPhase()).getStatus() != null) {
previousStatus = deliverable.getDeliverableInfo(this.getActualPhase()).getStatus();
}

// Deliverable shared Projects List
if (this.deliverable.getProjectDeliverableShareds() != null) {
this.deliverable.setSharedDeliverables(new ArrayList<>(this.deliverable.getProjectDeliverableShareds()
Expand Down Expand Up @@ -4379,6 +4390,46 @@ public void saveUsers() {
}
}

/**
* Notify to shared clusters with trainees information if the status of the current deliverable change
*
* @param statusPrevName - The previous deliverable status name.
* @param statusCurrentName The current deliverable status name.
* @param sharedClusterAcronym The acronym of the shared cluster.
* @param sharedClusterLeaderName The name of the shared cluster leader.
* @param sharedClusterLeaderEmail The email of the shared cluster leader.
*/
public void sendNotificationEmail(String statusPrevName, String statusCurrentName, String sharedClusterAcronym,
String sharedClusterLeaderName, String sharedClusterLeaderEmail) {

String toEmail = sharedClusterLeaderEmail;
// CC will be the user who is making the modification.
String ccEmail = this.getCurrentUser().getEmail();
// BBC will be our gmail notification email.
String bbcEmails = this.config.getEmailNotification();
String subject = this.getText("email.change.deliverableStatus.subject",
new String[] {deliverableID + "", statusPrevName, statusCurrentName});

// Building the email message
StringBuilder message = new StringBuilder();
String[] values = new String[7];

values[0] = sharedClusterLeaderName;
values[1] = deliverableID + "";
values[2] = deliverable.getProject().getAcronym();
values[3] = statusPrevName;
values[4] = statusCurrentName;
values[5] = sharedClusterAcronym;
values[6] = deliverable.getProject().getLeaderPerson(this.getActualPhase()).getUser().getComposedName();

message.append(this.getText("email.change.deliverableStatus.body", values));
message.append(this.getText("email.support.noCrpAdmins"));
message.append(this.getText("email.getStarted"));
message.append(this.getText("email.bye"));

sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true);
}

public void setAcceptationPercentage(Integer acceptationPercentage) {
this.acceptationPercentage = acceptationPercentage;
}
Expand Down Expand Up @@ -4619,6 +4670,8 @@ private Deliverable updateDeliverableInfo() {
Deliverable deliverableBase = deliverableManager.getDeliverableById(deliverableID);
DeliverableInfo deliverableInfoDb = deliverableBase.getDeliverableInfo(this.getActualPhase());

this.validateStatusChangeAndNotifySharedClusters();

deliverableInfoDb.setTitle(deliverable.getDeliverableInfo(this.getActualPhase()).getTitle());
deliverableInfoDb.setDescription(deliverable.getDeliverableInfo(this.getActualPhase()).getDescription());

Expand Down Expand Up @@ -4740,4 +4793,57 @@ public void validate() {
}
}

/**
* Validate if the status change for the current deliverable and notify via email to shared clusters with trainees
* information
*/
public void validateStatusChangeAndNotifySharedClusters() {
try {
if (this.hasSpecificities(APConstants.DELIVERABLE_SHARED_CLUSTERS_TRAINEES_ACTIVE)) {

// Store repeated values in local variables for better readability and performance
int statusPrev = previousStatus;
String statusPrevName = ProjectStatusEnum.getValue(statusPrev).name();
int currentPhaseStatus = deliverable.getDeliverableInfo(this.getActualPhase()).getStatus();
String statusCurrentName = ProjectStatusEnum.getValue(currentPhaseStatus).name();

// Validate previous deliverable status
boolean isNotExtendedOrCancelled = statusPrev != Integer.parseInt(ProjectStatusEnum.Extended.getStatusId())
&& statusPrev != Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId());
boolean isCurrentlyExtendedOrCancelled =
currentPhaseStatus == Integer.parseInt(ProjectStatusEnum.Extended.getStatusId())
|| currentPhaseStatus == Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId());

if (isNotExtendedOrCancelled && isCurrentlyExtendedOrCancelled && deliverable.getClusterParticipant() != null
&& !deliverable.getClusterParticipant().isEmpty()) {

for (DeliverableClusterParticipant deliverableParticipant : deliverable.getClusterParticipant()) {
if (deliverableParticipant != null && deliverableParticipant.getProject() != null
&& deliverableParticipant.getProject().getId() != null
&& !deliverableParticipant.getProject().getId().equals(deliverable.getProject().getId())) {

// Get shared cluster leader information
Project sharedCluster = new Project();
if (deliverableParticipant.getProject().getId() != null) {
sharedCluster = projectManager.getProjectById(deliverableParticipant.getProject().getId());
}
String sharedClusterLeaderName = null, sharedClusterLeaderEmail = null;
User lead = sharedCluster.getLeaderPerson(this.getActualPhase()).getUser();
if (lead != null) {
sharedClusterLeaderName = lead.getFirstName();
sharedClusterLeaderEmail = lead.getEmail();
}

// Send notification email
this.sendNotificationEmail(statusPrevName, statusCurrentName, sharedCluster.getAcronym(),
sharedClusterLeaderName, sharedClusterLeaderEmail);
}
}
}
}
} catch (NumberFormatException | NullPointerException e) {
logger.error("Error occurred while processing shared cluster information and sending email: " + e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,5 @@ public void validate() {
super.validate();
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ private void notifyRoleAssigned(User userAssigned, Role role) {
if (role.getId() == pcRole.getId().longValue()) {
ProjectPartnerPerson projectLeader = project.getLeaderPersonDB(this.getActualPhase());
if (projectLeader != null && projectLeader.getUser() != null && projectLeader.getUser().getEmail() != null) {
ccEmail +=", " + projectLeader.getUser().getEmail();
ccEmail += ", " + projectLeader.getUser().getEmail();
}
}

Expand Down Expand Up @@ -900,7 +900,7 @@ private void notifyRoleUnassigned(User userUnassigned, Role role) {
if (role.getId() == pcRole.getId().longValue()) {
ProjectPartnerPerson projectLeader = project.getLeaderPersonDB(this.getActualPhase());
if (projectLeader != null && projectLeader.getUser() != null && projectLeader.getUser().getEmail() != null) {
ccEmail +=", " + projectLeader.getUser().getEmail();
ccEmail += ", " + projectLeader.getUser().getEmail();
}
}

Expand Down Expand Up @@ -2310,13 +2310,4 @@ public void validate() {
}
}


private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,5 @@ private void submitProject() {
}
}

private boolean validateEmailNotification() {
GlobalUnit globalUnit = loggedCrp;
Boolean crpNotification = globalUnit.getCustomParameters().stream()
.filter(c -> c.getParameter().getKey().equalsIgnoreCase(APConstants.CRP_EMAIL_NOTIFICATIONS))
.allMatch(t -> (t.getValue() == null) ? true : t.getValue().equalsIgnoreCase("true"));
return crpNotification;
}


}
6 changes: 6 additions & 0 deletions marlo-web/src/main/resources/custom/aicrra.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2859,6 +2859,12 @@ email.contactpoint.responsabilities=<li>Set up and edit funding sources, and ass
email.contactpoint.unassigned.subject=[AICCRA] Your role as Contact Point of {0} {1} has been removed.
email.contactpoint.unassigned=Your role in AICCRA as contact point of the {0} {1} has been removed.<br><br>

#email Deliverable change status subject
email.change.deliverableStatus.subject=[AICCRA] Deliverable D{0} has been change its status from {1} to {2}

#email Deliverable change status body
email.change.deliverableStatus.body=Dear {0}, <br><br>The deliverable <b>D{1}</b> from {2} Cluster has changed its status from <b>{3}</b> to <b>{4}</b>. This is currently shared with your Cluster {5} with trainees information. <br><br>Please contact the cluster leader {6} of {2} cluster for more information.<br><br>

#email Tracking comment subject
email.tracking.comment.subject=[AICCRA] QA module from {0} cluster on {1} section has been {2}

Expand Down
6 changes: 6 additions & 0 deletions marlo-web/src/main/resources/global.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,12 @@ email.contactpoint.responsabilities=<li>Set up and edit funding sources, and ass
email.contactpoint.unassigned.subject=[MARLO] Your role as Contact Point of {0} {1} has been removed.
email.contactpoint.unassigned=Your role in MARLO as contact point of the {0} {1} has been removed.<br><br>

#email Deliverable change status subject
email.change.deliverableStatus.subject=[AICCRA] Deliverable D{0} has been change its status from {1} to {2}

#email Deliverable change status body
email.change.deliverableStatus.body=Dear {0}, <br><br>The deliverable <b>D{1}</b> from {2} Cluster has changed its status from <b>{3}</b> to <b>{4}</b>.<br>This is currently shared with your Cluster {5} with trainees information. <br><br>Please contact the cluster leader {6} of {2} cluster for more information.<br><br>

#email Tracking comment subject
email.tracking.comment.subject=[AICCRA] QA module from {0} {1} has been {2}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
</a>
[#else]
<div class="icon-container remove-disabled">
<span class="trash-icon glyphicon glyphicon-trash" title="This deliverable cannot be deleted [#if canDeleteDeliverableWithSharedTrainees]due it has trainees information from submitted shared clusters[/#if]"></span>
<span class="trash-icon glyphicon glyphicon-trash" title="This deliverable cannot be deleted [#if !canDeleteDeliverableWithSharedTrainees]due it has trainees information from submitted shared clusters[/#if]"></span>
<div>
[/#if]
</td>
Expand Down
5 changes: 4 additions & 1 deletion marlo-web/src/main/webapp/crp/js/home/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ function initDashboard() {
$(".timelineRefresh").hide();
$(".timeline").show();
setTimelinePosition();
getIntersectedActivities();
setTimeout(() => {
getIntersectedActivities();
}, 200);


$('.buttonRightTimeline').on("click", moveScrollRight);

Expand Down

0 comments on commit 69b4d63

Please sign in to comment.