Skip to content

Commit e518c33

Browse files
committed
Merge branch 'aiccra-staging' into aiccra-feature-A2-569
2 parents 19d0d5d + 7361ad2 commit e518c33

File tree

5 files changed

+187
-46
lines changed

5 files changed

+187
-46
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*****************************************************************
2+
* This file is part of Managing Agricultural Research for Learning &
3+
* Outcomes Platform (MARLO).
4+
* MARLO is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* at your option) any later version.
8+
* MARLO is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
* You should have received a copy of the GNU General Public License
13+
* along with MARLO. If not, see <http://www.gnu.org/licenses/>.
14+
*****************************************************************/
15+
16+
package org.cgiar.ccafs.marlo.action.json.global;
17+
18+
import org.cgiar.ccafs.marlo.action.BaseAction;
19+
import org.cgiar.ccafs.marlo.utils.APConfig;
20+
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
24+
import javax.inject.Inject;
25+
26+
import org.apache.struts2.dispatcher.Parameter;
27+
28+
29+
public class ProgressActiveValidationAction extends BaseAction {
30+
31+
32+
/**
33+
*
34+
*/
35+
private static final long serialVersionUID = 8027160696406597679L;
36+
/**
37+
*
38+
*/
39+
private Map<String, String> status;
40+
41+
@Inject
42+
public ProgressActiveValidationAction(APConfig config) {
43+
super(config);
44+
}
45+
46+
@Override
47+
public String execute() throws Exception {
48+
49+
status = new HashMap<>();
50+
51+
if (this.isUpKeepActive()) {
52+
status.put("isProgress", "true");
53+
} else {
54+
status.put("isProgress", "false");
55+
}
56+
57+
return SUCCESS;
58+
}
59+
60+
public Map<String, String> getStatus() {
61+
return status;
62+
}
63+
64+
@Override
65+
public void prepare() throws Exception {
66+
Map<String, Parameter> parameters = this.getParameters();
67+
}
68+
69+
70+
public void setStatus(Map<String, String> keyOutputs) {
71+
this.status = keyOutputs;
72+
}
73+
}
74+

marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/PartnersSaveAction.java

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@
4646
import org.cgiar.ccafs.marlo.utils.SendMailS;
4747

4848
import java.util.Collection;
49-
import java.util.HashMap;
5049
import java.util.List;
51-
import java.util.Map;
5250
import java.util.logging.Level;
5351
import java.util.stream.Collectors;
5452

5553
import javax.inject.Inject;
5654

57-
import com.fasterxml.jackson.core.JsonProcessingException;
58-
import com.fasterxml.jackson.databind.ObjectMapper;
5955
import org.apache.commons.lang3.StringUtils;
56+
import org.apache.http.auth.UsernamePasswordCredentials;
57+
import org.apache.http.client.methods.CloseableHttpResponse;
58+
import org.apache.http.client.methods.HttpPost;
59+
import org.apache.http.entity.StringEntity;
60+
import org.apache.http.impl.auth.BasicScheme;
61+
import org.apache.http.impl.client.CloseableHttpClient;
62+
import org.apache.http.impl.client.HttpClients;
63+
import org.json.JSONObject;
6064
import org.slf4j.Logger;
6165
import org.slf4j.LoggerFactory;
6266

@@ -448,13 +452,6 @@ public String save() {
448452
boolean postFailed = false;
449453
if (this.isAiccra()) {
450454

451-
Map<String, Object> request = new HashMap<>();
452-
request.put("name", partnerRequest.getPartnerName());
453-
request.put("acronym", partnerRequest.getAcronym());
454-
request.put("websiteLink", partnerRequest.getWebPage());
455-
request.put("institutionTypeCode", partnerRequest.getInstitutionType().getId());
456-
request.put("hqCountryIso", partnerRequest.getLocElement().getIsoAlpha2());
457-
458455
// setting requestSource CLARISA parameter
459456
String requestSource;
460457
if (project != null && project.getAcronym() != null) {
@@ -464,30 +461,8 @@ public String save() {
464461
} else {
465462
requestSource = "Request made from AICCRA";
466463
}
467-
request.put("requestSource", requestSource);
468-
469-
request.put("misAcronym", "aiccra");
470-
request.put("userId", this.getCurrentUser().getId());
471-
request.put("externalUserMail", this.getCurrentUser().getEmail());
472-
request.put("externalUserName", this.getCurrentUser().getUsername());
473-
request.put("externalUserComments", "Request made from AICCRA");
474-
475-
ObjectMapper mapper = new ObjectMapper();
476-
477-
try {
478-
String requestStr = mapper.writeValueAsString(request);
479464

480-
ExternalPostUtils epu = new ExternalPostUtils();
481-
epu.setUsername(config.getClarisaAPIUsername());
482-
epu.setPassword(config.getClarisaAPIPassword());
483-
String responseStr = epu.postJson(config.getClarisaAPIHost() + "/api/partner-requests/create", requestStr);
484-
485-
if (responseStr.isEmpty()) {
486-
postFailed = true;
487-
}
488-
} catch (JsonProcessingException ex) {
489-
java.util.logging.Logger.getLogger(PartnersSaveAction.class.getName()).log(Level.SEVERE, null, ex);
490-
}
465+
this.sendPartnerRequest(partnerRequestModifications, requestSource, postFailed);
491466

492467
} else {
493468
partnerRequest = partnerRequestManager.savePartnerRequest(partnerRequest);
@@ -535,6 +510,60 @@ public String save() {
535510
}
536511
}
537512

513+
/**
514+
* send request to CLARISA,to create a partner
515+
*
516+
* @param PartnerRequest partnerRequest
517+
* @param String requestSource
518+
* @param boolean postFailed
519+
* @author IBD
520+
*/
521+
public void sendPartnerRequest(PartnerRequest partnerRequest, String requestSource, boolean postFailed) {
522+
523+
try {
524+
525+
ExternalPostUtils epu = new ExternalPostUtils();
526+
epu.setUsername(config.getClarisaAPIUsername());
527+
epu.setPassword(config.getClarisaAPIPassword());
528+
JSONObject jsonObject = new JSONObject();
529+
530+
531+
jsonObject.put("name", partnerRequest.getPartnerName());
532+
jsonObject.put("acronym", partnerRequest.getAcronym());
533+
jsonObject.put("websiteLink", partnerRequest.getWebPage());
534+
jsonObject.put("institutionTypeCode", partnerRequest.getInstitutionType().getId());
535+
jsonObject.put("hqCountryIso", partnerRequest.getLocElement().getIsoAlpha2());
536+
537+
jsonObject.put("requestSource", requestSource);
538+
539+
jsonObject.put("misAcronym", "aiccra");
540+
jsonObject.put("userId", this.getCurrentUser().getId());
541+
jsonObject.put("externalUserMail", this.getCurrentUser().getEmail());
542+
jsonObject.put("externalUserName", this.getCurrentUser().getUsername());
543+
jsonObject.put("externalUserComments", "Request made from AICCRA");
544+
545+
HttpPost httpPost = new HttpPost(config.getClarisaAPIHost() + "/api/partner-requests/create");
546+
547+
httpPost.setEntity(new StringEntity(jsonObject.toString()));
548+
549+
httpPost.setHeader("Accept", "application/json");
550+
httpPost.setHeader("Content-Type", "application/json");
551+
httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(epu.getUsername(), epu.getPassword()),
552+
"UTF-8", false));
553+
554+
CloseableHttpClient httpClient = HttpClients.createDefault();
555+
556+
CloseableHttpResponse response = httpClient.execute(httpPost);
557+
558+
LOG.info(" Class [" + PartnersSaveAction.class.getName()
559+
+ "] - function [sendPartnerRequest] - variable [response] " + response);
560+
} catch (Exception e) {
561+
postFailed = true;
562+
java.util.logging.Logger.getLogger(PartnersSaveAction.class.getName()).log(Level.SEVERE, null, e);
563+
}
564+
565+
}
566+
538567
public void setActivityID(int activityID) {
539568
this.activityID = activityID;
540569
}

marlo-web/src/main/resources/struts-json.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
<param name="excludeNullProperties">true</param>
2727
</result>
2828
</action>
29+
30+
<action name="isProgressActive"
31+
class="org.cgiar.ccafs.marlo.action.json.global.ProgressActiveValidationAction">
32+
<result type="json">
33+
<param name="noCache">true</param>
34+
<param name="excludeNullProperties">true</param>
35+
</result>
36+
</action>
2937

3038
<action name="uploadFundingSource"
3139
class="org.cgiar.ccafs.marlo.action.json.project.UploadFundingSourceFileAction">

marlo-web/src/main/webapp/crp/js/projects/deliverables/deliverableInfo.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,12 @@ var deliverablePartnersModule = (function () {
749749

750750
function addPartnerItem() {
751751
var $listBlock = $('.otherDeliverablePartners');
752-
var $newItem = $('#deliverablePartnerItem-template').clone(true).removeAttr('id');
752+
var $template = $('#deliverablePartnerItem-template');
753+
$template.find('select').select2("destroy");
754+
var $newItem = $template.clone(true).removeAttr('id');
755+
756+
$template.find('select').select2();
757+
$newItem.find('select').select2();
753758
$listBlock.append($newItem);
754759
$newItem.show();
755760
updateIndexes();

marlo-web/src/main/webapp/crp/js/projects/deliverables/deliverableShfrm.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ function init() {
6464
setViewMore();
6565
});
6666

67+
// $(".deliverableList").select2();
68+
6769
$("textarea[id!='justification']").autoGrow();
68-
$(".deliverableList").on("change", addDeliverable);
70+
$(".deliverableList").on("change", addSubactionsEvent);
6971
}
7072

71-
// Add a new deliverable element
72-
function addDeliverable() {
73+
// Add a new subAction element
74+
function addSubactionsEvent() {
7375
var option = $(this).find("option:selected");
7476
var canAdd = true;
7577
if (option.val() == "-1") {
@@ -90,6 +92,7 @@ function addDeliverable() {
9092
// Reset select
9193
$(this).val("-1");
9294
$(this).trigger('change.select2');
95+
$(this).select2("destroy").select2();
9396

9497
if (!canAdd) {
9598
return;
@@ -102,12 +105,24 @@ function addDeliverable() {
102105
$item.find(".id").val(option.val());
103106
$list.append($item);
104107
$item.show('slow');
108+
105109
// var $actionContainer = $(this).parents(".fullPartBlock");
106110
// var activityIndex = $activity.find(".index").html();
107111
// updateDeliverable(this);
108112
updateActionsAndSubActionsIndexes();
109113
checkItems($list);
110114

115+
disabledOption(this, option.val());
116+
}
117+
118+
function disabledOption(element, value) {
119+
$(element).find(`option[value="${value}"]`).attr('disabled', true);
120+
$(element).find('select').select2("destroy").select2();
121+
}
122+
123+
function enablesOption(element, value) {
124+
$(element).parents('.subSectionsSelector').find('select').find(`option[value="${value}"]`).removeAttr('disabled');
125+
$(element).parents('.subSectionsSelector').find('select').select2("destroy").select2();
111126
}
112127

113128
function checkItems(block) {
@@ -197,8 +212,8 @@ function attachEvents() {
197212
* Project partner Events
198213
*/
199214
// Add a project partner Event
200-
$(".elementType-shfrmPriorityAction-deliverablePriorityActions").on("change", addPartnerEvent);
201-
$(".removeElementType-shfrmPriorityAction-deliverablePriorityActions").on('click', removePartnerEvent);
215+
$(".elementType-shfrmPriorityAction-deliverablePriorityActions").on("change", addActionEvent);
216+
$(".removeElementType-shfrmPriorityAction-deliverablePriorityActions").on('click', removeActionEvent);
202217
$(".removeElementType-shfrmPriorityAction-deliverablePriorityActions").on('mouseenter', function () {
203218
currentDeleteActionId = $(this).parent('.relationElement').find('.elementRelationID').val();
204219
});
@@ -585,7 +600,7 @@ function setPartnerTypeToDefault(type) {
585600
}
586601

587602
let currentDeleteActionId = null;
588-
function removePartnerEvent(e) {
603+
function removeActionEvent() {
589604
$(`input.actionidvalue[value="${currentDeleteActionId}"]`).parents('.projectPartner').remove();
590605
updateActionsAndSubActionsIndexes();
591606
}
@@ -603,35 +618,46 @@ function updateActionsAndSubActionsIndexes() {
603618
}
604619

605620
function removeSubActionEvent() {
606-
$(this).parents('.deliverableActivity').remove();
621+
const value = $(this).parents('.deliverableActivity').find('input.id').val();
607622
updateActionsAndSubActionsIndexes();
623+
enablesOption(this, value);
624+
$(this).parents('.deliverableActivity').remove();
625+
608626
}
609627

610-
function addPartnerEvent(e) {
628+
function addActionEvent(e) {
611629
var option = $(this).find("option:selected");
612630
var $newElement = $("#projectPartner-template").clone(true).removeAttr("id");
613631
$newElement.find(".actionidvalue").val(option.val());
614632

615633
let itemsSize = Number($('#projectPartnersBlock').find('.projectPartner').length ?? 0);
616634
itemsSize && itemsSize++;
617635

636+
$newElement.find(".id").val(option.val());
618637
$newElement.find(".index_number").html(itemsSize);
619638
$newElement.find(".priorityActionTitle").html($(option).text());
620639
$newElement.find(".subActionsSelector").html(cloneSubActionSelect(option.val()));
621640

622641
console.log($('#projectPartnersBlock'))
623642
$('#projectPartnersBlock').append($newElement);
643+
$newElement.find("select").find('select').select2("destroy").select2();
644+
624645
$newElement.show("slow", function () {
625646
$(document).trigger('updateComponent');
626-
$newElement.find("select").select2();
647+
$newElement.trigger('change.select2');
627648
});
628649

629650
updateActionsAndSubActionsIndexes();
651+
checkItems($('#projectPartnersBlock'));
630652
}
631653

632654
function cloneSubActionSelect(value) {
633-
var $select = $(`#subactionSelect-${value}`).find('.baseselect').clone(true);
655+
var $original =$(`#subactionSelect-${value}`).find('.baseselect');
656+
$original.find('select').select2("destroy");
657+
var $select = $original.clone(true);
634658
$select.removeClass('hideSelect');
659+
$original.find('select').select2();
660+
$select.find('select').select2();
635661
return $select;
636662
}
637663

@@ -800,7 +826,6 @@ function addSelect2() {
800826
$("form select.setSelect2 ").select2({
801827
width: '100%'
802828
});
803-
804829
}
805830

806831
/**

0 commit comments

Comments
 (0)