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 8, 2024
2 parents d376cc9 + 391ce36 commit b655af3
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.cgiar.ccafs.marlo.data.manager.CrpProgramManager;
import org.cgiar.ccafs.marlo.data.manager.CrpProgramOutcomeManager;
import org.cgiar.ccafs.marlo.data.manager.CustomParameterManager;
import org.cgiar.ccafs.marlo.data.manager.DeliverableClusterParticipantManager;
import org.cgiar.ccafs.marlo.data.manager.DeliverableCrpOutcomeManager;
import org.cgiar.ccafs.marlo.data.manager.DeliverableInfoManager;
import org.cgiar.ccafs.marlo.data.manager.DeliverableManager;
Expand Down Expand Up @@ -416,6 +417,9 @@ public class BaseAction extends ActionSupport implements Preparable, SessionAwar
@Inject
private ButtonGuideContentManager buttonGuideContentManager;

@Inject
private DeliverableClusterParticipantManager deliverableClusterParticipantManager;

private String centerSession;

private Long centerID;
Expand Down Expand Up @@ -1111,6 +1115,44 @@ public boolean canDeleteActivity(long activityTitleID) {
return canDelete;
}

/**
* @author KTANAKA
* @param deliverableID
* @param phaseID
* @return boolean - true if the deliverable with shared clusters with trainees information can be deleted
*/
public boolean canDeleteDeliverableWithSharedTrainees(long deliverableID, long phaseID) {
try {
// Check if the shared cluster trainees specificity is active
if (this.hasSpecificities(APConstants.DELIVERABLE_SHARED_CLUSTERS_TRAINEES_ACTIVE)) {
// Check if there is no submission in progress phase
if (!this.isProgressActive()) {
// Retrieve deliverable cluster participants
List<DeliverableClusterParticipant> deliverableClusterParticipants = deliverableClusterParticipantManager
.getDeliverableClusterParticipantByDeliverableAndPhase(deliverableID, phaseID);

// Check if the list is not empty and process each participant
if (deliverableClusterParticipants != null && !deliverableClusterParticipants.isEmpty()) {
for (DeliverableClusterParticipant deliverableShared : deliverableClusterParticipants) {
Project project = deliverableShared.getProject();
Deliverable deliverable = deliverableShared.getDeliverable();
// Ensure necessary objects are not null and IDs are different, then check submission status
if (this.isSubmit(project.getId())) {
// Return false if submission is found
return false;
}
}
}
}
}
} catch (Exception e) {
// Log error if an exception occurs
LOG.error("Error getting shared clusters statuses", e);
}
// Return false if no submission is found or an error occurred
return true;
}

/**
* Make the validation for CRP Admin, PMU or Finance Manager role to
* determinate if a Funding source can be duplicated.
Expand Down Expand Up @@ -1326,7 +1368,6 @@ public boolean canManageFeedback(Long projectID) {
return response;
}


/**
* Validate the user permission to replay or react to a comment
*
Expand Down Expand Up @@ -2909,7 +2950,6 @@ public List<Deliverable> getDeliverableRelationsImpact(Long id, String className

}


public List<Deliverable> getDeliverableRelationsProject(Long id, String className, Long projectID) {
Class<?> clazz;
List<Deliverable> deliverables = null;
Expand Down Expand Up @@ -3454,7 +3494,6 @@ public List<HistoryDifference> getDifferences() {
return this.differences;
}


/**
* Get information for duplicated deliverables - Validation by DOI, Handle and Dissemination URL
*
Expand Down Expand Up @@ -8765,7 +8804,6 @@ public boolean validateCenterTopic(CrpProgram program, String sectionName) {
return true;
}


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
@@ -0,0 +1,107 @@
/*****************************************************************
* This file is part of Managing Agricultural Research for Learning &
* Outcomes Platform (MARLO).
* MARLO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
* MARLO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with MARLO. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************/

package org.cgiar.ccafs.marlo.action.json.project;

import org.cgiar.ccafs.marlo.action.BaseAction;
import org.cgiar.ccafs.marlo.config.APConstants;
import org.cgiar.ccafs.marlo.data.manager.DeliverableClusterParticipantManager;
import org.cgiar.ccafs.marlo.data.model.DeliverableClusterParticipant;
import org.cgiar.ccafs.marlo.data.model.Project;
import org.cgiar.ccafs.marlo.utils.APConfig;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author kenjitm
*/
public class CanDeleteDeliverableWithSharedTrainees extends BaseAction {

private static final long serialVersionUID = -8182788196525839215L;
private Map<String, Object> canDelete;
private long deliverableID;
private long phaseID;
private DeliverableClusterParticipantManager deliverableClusterParticipantManager;
private final Logger logger = LoggerFactory.getLogger(CanDeleteDeliverableWithSharedTrainees.class);

@Inject
public CanDeleteDeliverableWithSharedTrainees(APConfig config,
DeliverableClusterParticipantManager deliverableClusterParticipantManager) {
super(config);
this.deliverableClusterParticipantManager = deliverableClusterParticipantManager;
}

@Override
public String execute() throws Exception {
boolean response = true;
try {
// Check if the shared cluster trainees specificity is active
if (this.hasSpecificities(APConstants.DELIVERABLE_SHARED_CLUSTERS_TRAINEES_ACTIVE)) {
// Check if there is no submission in progress phase
if (!this.isProgressActive()) {
// Retrieve deliverable cluster participants
List<DeliverableClusterParticipant> deliverableClusterParticipants = deliverableClusterParticipantManager
.getDeliverableClusterParticipantByDeliverableAndPhase(deliverableID, phaseID);

// Check if the list is not empty and process each participant
if (deliverableClusterParticipants != null && !deliverableClusterParticipants.isEmpty()) {
for (DeliverableClusterParticipant deliverableShared : deliverableClusterParticipants) {

Project project = deliverableShared.getProject();
// Ensure necessary objects are not null and IDs are different, then check submission status
if (this.isSubmit(project.getId())) {
// Return true if submission is found
response = false;
}
}
}

}
}
} catch (Exception e) {
// Log error if an exception occurs
logger.error("Error getting shared clusters statuses", e);
}
canDelete = new HashMap<String, Object>();
canDelete.put("response", response);

return SUCCESS;
}

public Map<String, Object> getCanDelete() {
return canDelete;
}

@Override
public void prepare() throws Exception {
Map<String, Parameter> parameters = this.getParameters();
deliverableID = Long.parseLong(StringUtils.trim(parameters.get(APConstants.DELIVERABLE_ID).getMultipleValues()[0]));
phaseID = Long.parseLong(StringUtils.trim(parameters.get(APConstants.PHASE_ID).getMultipleValues()[0]));
}

public void setCanDelete(Map<String, Object> canDelete) {
this.canDelete = canDelete;
}

}
8 changes: 8 additions & 0 deletions marlo-web/src/main/resources/struts-json.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@
<param name="excludeNullProperties">true</param>
</result>
</action>

<action name="canDeleteDeliverableWithSharedTrainees"
class="org.cgiar.ccafs.marlo.action.json.project.CanDeleteDeliverableWithSharedTrainees">
<result type="json">
<param name="noCache">true</param>
<param name="excludeNullProperties">true</param>
</result>
</action>

<action name="unsubmitImpactpathway"
class="org.cgiar.ccafs.marlo.action.json.impactpathway.UnSubmitImpactpathwayAction">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
[#assign currentSectionString = "${actionName?replace('/','-')}-phase-${(actualPhase.id)!}" /]
[#assign pageLibs = ["jQuery-Timelinr","cytoscape","cytoscape-panzoom","cytoscape-qtip","qtip2","datatables.net", "datatables.net-bs"] /]
[#assign customJS = [
"${baseUrlMedia}/js/home/dashboard.js?20240226",
"${baseUrlMedia}/js/home/dashboard.js?20240508",
"${baseUrlCdn}/global/js/impactGraphic.js"
]
/]
[#assign customCSS = [
"${baseUrlMedia}/css/home/dashboard.css?20240226",
"${baseUrlMedia}/css/home/dashboard.css?20240507",
"${baseUrlCdn}/global/css/customDataTable.css",
"${baseUrlCdn}/global/css/impactGraphic.css",
"https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

<input type="hidden" id="traineesIndicator" name="traineesIndicator" value="${(action.getTraineesIndicatorDB())!''}"/>
<input type="hidden" name="deliverable.deliverableInfo.remainingPending" value="${(deliverable.deliverableInfo.remainingPending!'false')?c}"/>
<input type="hidden" id="adminRole" name="adminRole" value="${((action.canEditCrpAdmin())!'false')?c}"/>

<div class="simpleBox">
[#-- Title input --]
<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[#assign currentSectionString = "project-${actionName?replace('/','-')}-${deliverableID}-phase-${(actualPhase.id)!}" /]
[#assign pageLibs = ["select2","font-awesome","dropzone","blueimp-file-upload","jsUri", "flag-icon-css", "pickadate", "vue"] /]
[#assign customJS = [
"${baseUrlMedia}/js/projects/deliverables/deliverableInfo.js?20240123",
"${baseUrlMedia}/js/projects/deliverables/deliverableInfo.js?20240508",
"${baseUrlMedia}/js/projects/deliverables/deliverableShfrm.js?20240226",
"${baseUrlMedia}/js/projects/deliverables/deliverableDissemination.js?20240322",
"${baseUrlMedia}/js/projects/deliverables/deliverableQualityCheck.js?20220721",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
[#if isDeliverableNew]<span class="label label-info">New</span>[/#if]
[#-- Owner --]
[#local isOwner = (deliverable.project.id == projectID)!false]
[#-- can delete deliverable with shared trainees --]
[#local canDeleteDeliverableWithSharedTrainees = (action.canDeleteDeliverableWithSharedTrainees(deliverable.id, actualPhase.id))!false]

[#if deliverable.deliverableInfo.title?has_content]
<a href="[@s.url namespace=namespace action=defaultAction] [@s.param name='deliverableID']${deliverable.id?c}[/@s.param][#include "/WEB-INF/global/pages/urlGlobalParams.ftl" /][/@s.url]" >
Expand Down Expand Up @@ -169,13 +171,15 @@
[/#if]
</td>
<td class="text-center">
[#-- Remove icon --]
[#if isDeliverableNew && isOwner]
[#-- Remove icon --]
[#if isDeliverableNew && isOwner && canDeleteDeliverableWithSharedTrainees]
<a id="removeDeliverable-${deliverable.id}" class="removeDeliverable" href="${baseUrl}/projects/${crpSession}/deleteDeliverable.do?deliverableID=${deliverable.id}&phaseID=${(actualPhase.id)!}" title="Remove deliverable">
<div class="icon-container"><span class="trash-icon glyphicon glyphicon-trash"></span><div>
</a>
[#else]
<div class="icon-container remove-disabled"><span class="trash-icon glyphicon glyphicon-trash" title="This deliverable cannot be deleted"></span><div>
<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>
<div>
[/#if]
</td>
[/#if]
Expand Down
Loading

0 comments on commit b655af3

Please sign in to comment.