Skip to content

Commit

Permalink
Merge branch 'aiccra-staging' into aiccra-marlo-java-11-version2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian45 committed Dec 18, 2024
2 parents 7fb662a + 6ad365d commit 1db9fdd
Show file tree
Hide file tree
Showing 19 changed files with 502 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ public final class APConstants {

public static final String IGNORE_NEWER_YEARS = "ignoreNewer";
public static final String DELIVERABLE_CRP_PROGRAM_OUTCOME_DEPRECATED = "DEPRECATED";
public static final String CRP_PROGRAM_OUTCOME_DEPRECATED = "DEPRECATED";

public static final int EXPECTED_OTHER_ALLIANCE_LEVER_ID = 9;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public interface DeliverableInfoDAO {
public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase);


/**
* This method gets a list of DeliverableInfo that are active by a given phase, project and status
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and project
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase) {
return deliverableInfos;
}

@Override
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId) {

StringBuilder query = new StringBuilder();
query.append("SELECT DISTINCT ");
query.append("di.id as id ");
query.append("FROM ");
query.append("deliverables_info AS di ");
query.append("INNER JOIN deliverables AS d ON d.id = di.deliverable_id ");
query.append("WHERE d.is_active = 1 AND ");
query.append("d.project_id IS NOT NULL AND ");
query.append("di.is_active = 1 AND ");
query.append("di.`id_phase` =" + phase.getId());
query.append(" AND d.project_id =" + projectId);
query.append(" AND di.status !=" + statusId);

List<Map<String, Object>> rList = super.findCustomQuery(query.toString());
List<DeliverableInfo> deliverableInfos = new ArrayList<>();

if (rList != null) {
for (Map<String, Object> map : rList) {
DeliverableInfo deliverableInfo = this.find(Long.parseLong(map.get("id").toString()));
deliverableInfos.add(deliverableInfo);
}
}

return deliverableInfos;
}


@Override
public List<DeliverableInfo> getDeliverablesInfoByProjectAndPhase(Phase phase, Project project) {
StringBuilder query = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public interface DeliverableInfoManager {

public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase);

/**
* This method gets a list of DeliverableInfo that are active by a given phase, project and status
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and type
*
Expand All @@ -80,14 +87,14 @@ public interface DeliverableInfoManager {
*/
List<DeliverableInfo> getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project);


/**
* This method gets a list of DeliverableInfo that are active by a given phase and type
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType);


public boolean isDeliverableSubcategoryIncludedWebsite(long deliverableID, Phase phase);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
package org.cgiar.ccafs.marlo.data.manager.impl;


import org.cgiar.ccafs.marlo.config.APConstants;
import org.cgiar.ccafs.marlo.data.dao.DeliverableActivityDAO;
import org.cgiar.ccafs.marlo.data.dao.PhaseDAO;
import org.cgiar.ccafs.marlo.data.manager.DeliverableActivityManager;
import org.cgiar.ccafs.marlo.data.model.DeliverableActivity;
import org.cgiar.ccafs.marlo.data.model.Phase;

import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;
import javax.inject.Named;
Expand All @@ -32,20 +36,60 @@ public class DeliverableActivityManagerImpl implements DeliverableActivityManage


private DeliverableActivityDAO deliverableActivityDAO;
private PhaseDAO phaseDAO;
// Managers


@Inject
public DeliverableActivityManagerImpl(DeliverableActivityDAO deliverableActivityDAO) {
public DeliverableActivityManagerImpl(DeliverableActivityDAO deliverableActivityDAO, PhaseDAO phaseDAO) {
this.deliverableActivityDAO = deliverableActivityDAO;
this.phaseDAO = phaseDAO;
}

@Override
public void deleteDeliverableActivity(long deliverableActivityId) {

DeliverableActivity deliverableActivity = this.getDeliverableActivityById(deliverableActivityId);

// Conditions to Project Innovation Works In AR phase and Upkeep Phase
if (deliverableActivity.getPhase().getDescription().equals(APConstants.PLANNING)
&& deliverableActivity.getPhase().getNext() != null) {
this.deleteDeliverableActivityPhase(deliverableActivity.getPhase().getNext(),
deliverableActivity.getDeliverable().getId(), deliverableActivity);
}

if (deliverableActivity.getPhase().getDescription().equals(APConstants.REPORTING)
&& deliverableActivity.getPhase().getNext() != null
&& deliverableActivity.getPhase().getNext().getNext() != null) {
Phase upkeepPhase = deliverableActivity.getPhase().getNext().getNext();
if (upkeepPhase != null) {
this.deleteDeliverableActivityPhase(upkeepPhase, deliverableActivity.getDeliverable().getId(),
deliverableActivity);
}
}

deliverableActivityDAO.deleteDeliverableActivity(deliverableActivityId);
}

public void deleteDeliverableActivityPhase(Phase next, long deliverableID, DeliverableActivity deliverableActivity) {
Phase phase = phaseDAO.find(next.getId());

List<DeliverableActivity> activityPrev =
deliverableActivityDAO.getDeliverableActivitiesByDeliverableIDAndPhase(deliverableID, phase.getId()).stream()
.filter(
r -> r.getActivity() != null && r.getActivity().getId() != null && deliverableActivity.getActivity() != null
&& r.getActivity().getId().equals(deliverableActivity.getActivity().getId()))
.collect(Collectors.toList());

for (DeliverableActivity deliverableActivityDB : activityPrev) {
deliverableActivityDAO.deleteDeliverableActivity(deliverableActivityDB.getId());
}

if (phase.getNext() != null) {
this.deleteDeliverableActivityPhase(phase.getNext(), deliverableID, deliverableActivity);
}
}

@Override
public boolean existDeliverableActivity(long deliverableActivityID) {

Expand Down Expand Up @@ -84,7 +128,47 @@ public DeliverableActivity getDeliverableActivityById(long deliverableActivityID
@Override
public DeliverableActivity saveDeliverableActivity(DeliverableActivity deliverableActivity) {

return deliverableActivityDAO.save(deliverableActivity);
DeliverableActivity activity = deliverableActivityDAO.save(deliverableActivity);
Phase phase = phaseDAO.find(activity.getPhase().getId());

// Conditions to Project Innovation Works In AR phase and Upkeep Phase
if (phase.getDescription().equals(APConstants.PLANNING) && phase.getNext() != null) {
this.saveDeliverableActivityPhase(activity.getPhase().getNext(), activity.getDeliverable().getId(),
deliverableActivity);
}

if (phase.getDescription().equals(APConstants.REPORTING)) {
if (phase.getNext() != null && phase.getNext().getNext() != null) {
Phase upkeepPhase = phase.getNext().getNext();
if (upkeepPhase != null) {
this.saveDeliverableActivityPhase(upkeepPhase, activity.getDeliverable().getId(), deliverableActivity);
}
}
}
return activity;
}

private void saveDeliverableActivityPhase(Phase next, Long deliverableID, DeliverableActivity deliverableActivity) {
Phase phase = phaseDAO.find(next.getId());

List<DeliverableActivity> deliverableActivityPrev =
deliverableActivityDAO.getDeliverableActivitiesByDeliverableIDAndPhase(deliverableID, phase.getId()).stream()
.filter(
r -> r.getActivity() != null && r.getActivity().getId() != null && deliverableActivity.getActivity() != null
&& r.getActivity().getId().equals(deliverableActivity.getActivity().getId()))
.collect(Collectors.toList());

if (deliverableActivityPrev.isEmpty()) {
DeliverableActivity deliverableActivitysAdd = new DeliverableActivity();
deliverableActivitysAdd.setDeliverable(deliverableActivity.getDeliverable());
deliverableActivitysAdd.setPhase(phase);
deliverableActivitysAdd.setActivity(deliverableActivity.getActivity());
deliverableActivitysAdd.setId(null);
deliverableActivityDAO.save(deliverableActivitysAdd);
}
if (phase.getNext() != null) {
this.saveDeliverableActivityPhase(phase.getNext(), deliverableID, deliverableActivity);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase) {
return deliverableInfoDAO.getDeliverablesInfoByPhase(phase);
}

@Override
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId) {
return deliverableInfoDAO.getDeliverablesInfoByPhaseProjectAndStatus(phase, projectId, statusId);
}


@Override
public List<DeliverableInfo> getDeliverablesInfoByProjectAndPhase(Phase phase, Project project) {
return deliverableInfoDAO.getDeliverablesInfoByProjectAndPhase(phase, project);
Expand All @@ -116,7 +122,6 @@ public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableT
return deliverableInfoDAO.getDeliverablesInfoByType(phase, deliverableType);
}


@Override
public boolean isDeliverableSubcategoryIncludedWebsite(long deliverableID, Phase phase) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,22 +658,40 @@ public String getInnovationsComposedName() {
}

try {
handle = deliverableTemp.getDeliverableMetadataElements().stream()
.filter(me -> me != null && me.getMetadataElement() != null && me.getMetadataElement().getId() != null
&& me.getMetadataElement().getId().longValue() == 35L && me.getDeliverable().getId().equals(this.getId())
&& !StringUtils.isBlank(me.getElementValue()))
.findFirst().orElse(null).getElementValue();
if (handle == null || handle.isEmpty()) {
handle = "Not defined";
if (deliverableTemp.getDeliverableMetadataElements() != null && this.getDeliverableInfo().getPhase() != null) {
deliverableTemp.setMetadataElements(new ArrayList<>(deliverableTemp.getDeliverableMetadataElements().stream()
.filter(c -> c.isActive() && c.getPhase().equals(this.getDeliverableInfo().getPhase())
&& c.getMetadataElement() != null && c.getMetadataElement().getId() != null
&& c.getMetadataElement().getId().longValue() == 35L && c.getDeliverable().getId().equals(this.getId())
&& !StringUtils.isBlank(c.getElementValue()))
.collect(Collectors.toList())));
if (deliverableTemp.getMetadataElements() != null && deliverableTemp.getMetadataElements().get(0) != null
&& deliverableTemp.getMetadataElements().get(0).getElementValue() != null
&& !deliverableTemp.getMetadataElements().get(0).getElementValue().isEmpty()) {
handle = "<p><small style=\"width: 100%;\">Handle: <a href=\""
+ deliverableTemp.getMetadataElements().get(0).getElementValue() + "\" target=\"_blank\">"
+ deliverableTemp.getMetadataElements().get(0).getElementValue();
}
}

} catch (Exception e) {
// error
}
try {

if (deliverableTemp.getDeliverableDisseminations() != null) {
deliverableTemp.setDisseminations(new ArrayList<>(deliverableTemp.getDeliverableDisseminations().stream()
.filter(c -> c.isActive() && c.getPhase().equals(this.getDeliverableInfo().getPhase()))
.collect(Collectors.toList())));
if (!deliverableTemp.getDisseminations().isEmpty()) {
deliverableTemp.setDissemination(deliverableTemp.getDisseminations().get(0));
} else {
deliverableTemp.setDissemination(new DeliverableDissemination());
}
}
if (deliverableTemp.getDissemination() != null
&& deliverableTemp.getDissemination().getDisseminationChannelName() != null) {
disseminationChannel = deliverableTemp.getDissemination().getDisseminationChannelName();
&& deliverableTemp.getDissemination().getDisseminationChannelName() != null
&& !deliverableTemp.getDissemination().getDisseminationChannelName().isEmpty()) {
disseminationChannel = " (" + deliverableTemp.getDissemination().getDisseminationChannelName() + ")";
}
} catch (Exception e) {
// error
Expand Down Expand Up @@ -735,9 +753,8 @@ public String getInnovationsComposedName() {
statusInfo = statusInfo.trim();
}
return "<div class=\"option_deliverable_inner_select_innovation\">" + "<p>D" + this.getId() + " - "
+ this.getDeliverableInfo().getTitle() + "</p>" + "<small style=\"width: 100%;\">Handle: <a href=\""
+ this.getDeliverableInfo().getTitle() + "\" target=\"_blank\">" + this.getDeliverableInfo().getTitle()
+ "</a></small>" + "<small style=\"width: 100%;\">Type: " + deliverableType + "</small>" + "</div>";
+ this.getDeliverableInfo().getTitle() + disseminationChannel + "</p>" + handle + "</a></small></p>"
+ "<small style=\"width: 100%;\">Type: " + deliverableType + "</small>" + "</div>";

} catch (Exception e) {
return "<b> (D" + this.getId() + ") </b> - " + this.getDeliverableInfo().getTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3052,9 +3052,13 @@ public void saveDataSharing() {
private void saveDeliverableActivities(Deliverable deliverablePrew) {
if (deliverable.getActivities() != null) {
if (deliverablePrew.getDeliverableActivities() != null && !deliverablePrew.getDeliverableActivities().isEmpty()) {
List<DeliverableActivity> activityPrew = deliverablePrew.getDeliverableActivities().stream()
.filter(dp -> dp.isActive() && dp.getPhase() != null && dp.getPhase().equals(this.getActualPhase()))
.collect(Collectors.toList());
/*
* List<DeliverableActivity> activityPrew = deliverablePrew.getDeliverableActivities().stream()
* .filter(dp -> dp.isActive() && dp.getPhase() != null && dp.getPhase().equals(this.getActualPhase()))
* .collect(Collectors.toList());
*/
List<DeliverableActivity> activityPrew = deliverableActivityManager
.getDeliverableActivitiesByDeliverableIDAndPhase(deliverableID, this.getActualPhase().getId());

for (DeliverableActivity deliverableActivity : activityPrew) {
if (!deliverable.getActivities().contains(deliverableActivity)) {
Expand All @@ -3064,15 +3068,17 @@ private void saveDeliverableActivities(Deliverable deliverablePrew) {
}

for (DeliverableActivity deliverableActivity : deliverable.getActivities()) {
if (deliverableActivity.getId() == null || deliverableActivity.getId() == -1) {

deliverableActivity.setDeliverable(deliverableManager.getDeliverableById(deliverableID));
deliverableActivity.setPhase(this.getActualPhase());
deliverableActivityManager.saveDeliverableActivity(deliverableActivity);
// This add projectFocus to generate correct auditlog.
deliverablePrew.getDeliverableActivities().add(deliverableActivity);
if (deliverableActivity.getId() != null && deliverableActivity.getId() != -1) {
deliverableActivity = deliverableActivityManager.getDeliverableActivityById(deliverableActivity.getId());
}

deliverableActivity.setDeliverable(deliverableManager.getDeliverableById(deliverableID));
deliverableActivity.setPhase(this.getActualPhase());
deliverableActivityManager.saveDeliverableActivity(deliverableActivity);
// This add projectFocus to generate correct auditlog.
deliverablePrew.getDeliverableActivities().add(deliverableActivity);
}

}
}

Expand Down
Loading

0 comments on commit 1db9fdd

Please sign in to comment.