From 4210794733c88c9656e884a861ab8718b2b5bbf3 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Tue, 5 Mar 2024 11:56:03 -0500 Subject: [PATCH 1/6] :wrench: chore(Contribution to performance indicators): Validate active crp milestones --- .../action/projects/ProjectOutcomeAction.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectOutcomeAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectOutcomeAction.java index 02443afe3c..4913d83b5d 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectOutcomeAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectOutcomeAction.java @@ -728,8 +728,8 @@ public void fillMilestonesProjectYearsList() { if (milestonesProject != null && !milestonesProject.isEmpty()) { milestonesProjectYear = new ArrayList<>(); for (CrpMilestone milestoneElement : milestonesProject) { - if (milestoneElement != null && milestoneElement.getYear() != null && !milestoneElement.getYear().equals(0) - && milestoneElement.getYear() <= this.getActualPhase().getYear()) { + if (milestoneElement != null && milestoneElement.isActive() && milestoneElement.getYear() != null + && !milestoneElement.getYear().equals(0) && milestoneElement.getYear() <= this.getActualPhase().getYear()) { milestonesProjectYear.add(milestoneElement.getYear()); } } @@ -1065,7 +1065,8 @@ public CrpMilestone getMilestoneYear(int year) { if (milestonesProject != null && !milestonesProject.isEmpty()) { try { projectMilestoneElement = milestonesProject.stream() - .filter(m -> m != null && m.getYear() != null && m.getYear() == year).collect(Collectors.toList()).get(0); + .filter(m -> m != null && m.isActive() && m.getYear() != null && m.getYear() == year) + .collect(Collectors.toList()).get(0); } catch (Exception e) { LOG.error(e + "error to get milestone by year"); } @@ -1544,10 +1545,12 @@ public void prepare() throws Exception { Set crpMilestones = new HashSet<>(); if (projectOutcome.getMilestones() != null) { for (ProjectMilestone crpMilestone : projectOutcome.getMilestones()) { - CrpMilestone milestone = crpMilestoneManager.getCrpMilestoneById(crpMilestone.getCrpMilestone().getId()); + if (crpMilestone != null && crpMilestone.getId() != null && crpMilestone.isActive()) { + CrpMilestone milestone = crpMilestoneManager.getCrpMilestoneById(crpMilestone.getCrpMilestone().getId()); - milestone.setIndex(crpMilestone.getId()); - crpMilestones.add(milestone); + milestone.setIndex(crpMilestone.getId()); + crpMilestones.add(milestone); + } // } } } From d81d4b90aaf0ac2a87174e113617e2f7a9120f89 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Tue, 5 Mar 2024 14:24:11 -0500 Subject: [PATCH 2/6] :wrench: chore(migration): Create TIP parameters table --- ...6_0_20240305_1400__CreateTipParametersTable.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1400__CreateTipParametersTable.sql diff --git a/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1400__CreateTipParametersTable.sql b/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1400__CreateTipParametersTable.sql new file mode 100644 index 0000000000..a0fbd8542a --- /dev/null +++ b/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1400__CreateTipParametersTable.sql @@ -0,0 +1,14 @@ +CREATE TABLE tip_parameters ( + id bigint(20) NOT NULL AUTO_INCREMENT, + tip_token_service text, + tip_login_service text, + tip_status_service text, + token_value text, + token_due_date TIMESTAMP NULL DEFAULT NULL, + private_key text, + tip_base_url text, + CONSTRAINT `PRIMARY` PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_general_ci; \ No newline at end of file From 6f1eb92ffd23063302337ab8697cf77a0415c401 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Tue, 5 Mar 2024 14:40:12 -0500 Subject: [PATCH 3/6] :wrench: chore(migration): Create TIP specificity --- .../main/java/org/cgiar/ccafs/marlo/config/APConstants.java | 1 + .../main/java/org/cgiar/ccafs/marlo/config/APConstants.java | 2 +- .../V2_6_0_20240305_1430__CreateTIPSpecificity.sql | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1430__CreateTIPSpecificity.sql diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java index 0ae4447c10..ddcf405fb7 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java @@ -151,6 +151,7 @@ public final class APConstants { "deliverable_shared_clusters_trainees_active"; public static final String HIGHLIGHT_COMMENTS_ACTIVE = "highlight_comments_active"; public static final String SHFRM_CONTRIBUTION_ACTIVE = "shfrm_contribution_active"; + public static final String TIP_SECTION_ACTIVE = "tip_section_active"; public static final String IS_EXPECTED_DELIVERABLE_REPORT_All_YEARS_VISIBLE = "is_expected_deliverable_report_all_years_visible"; diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java index dced0119bc..29095bf093 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/config/APConstants.java @@ -161,7 +161,7 @@ public final class APConstants { "deliverable_shared_clusters_trainees_active"; public static final String HIGHLIGHT_COMMENTS_ACTIVE = "highlight_comments_active"; public static final String SHFRM_CONTRIBUTION_ACTIVE = "shfrm_contribution_active"; - + public static final String TIP_SECTION_ACTIVE = "tip_section_active"; public static final String IS_EXPECTED_DELIVERABLE_REPORT_All_YEARS_VISIBLE = "is_expected_deliverable_report_all_years_visible"; diff --git a/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1430__CreateTIPSpecificity.sql b/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1430__CreateTIPSpecificity.sql new file mode 100644 index 0000000000..0714878978 --- /dev/null +++ b/marlo-web/src/main/resources/database/migrations/V2_6_0_20240305_1430__CreateTIPSpecificity.sql @@ -0,0 +1,6 @@ +INSERT INTO parameters (global_unit_type_id, `key`, `description`, `format`, default_value, category) +VALUES ( '1', 'tip_section_active', 'Enable TIP section', '1', 'false', '2'); +INSERT INTO parameters (global_unit_type_id, `key`, `description`, `format`, default_value, category) +VALUES ( '3', 'tip_section_active', 'Enable TIP section', '1', 'false', '2'); +INSERT INTO parameters (global_unit_type_id, `key`, `description`, `format`, default_value, category) +VALUES ( '4', 'tip_section_active', 'Enable TIP section', '1', 'false', '2'); \ No newline at end of file From 3c8373cfe5b18305d4863e11c43059fa8ce382d0 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Tue, 5 Mar 2024 15:05:35 -0500 Subject: [PATCH 4/6] :sparkles: feat(TIP integration): Create tip parameters model --- .../marlo/data/dao/TipParametersDAO.java | 67 +++++++++ .../data/dao/mysql/TipParametersMySQLDAO.java | 84 ++++++++++++ .../data/manager/TipParametersManager.java | 74 ++++++++++ .../impl/TipParametersManagerImpl.java | 77 +++++++++++ .../ccafs/marlo/data/model/TipParameters.java | 128 ++++++++++++++++++ .../main/resources/xmls/TipParameters.hbm.xml | 33 +++++ 6 files changed, 463 insertions(+) create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/TipParametersDAO.java create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/TipParametersManager.java create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/TipParametersManagerImpl.java create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java create mode 100644 marlo-data/src/main/resources/xmls/TipParameters.hbm.xml diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/TipParametersDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/TipParametersDAO.java new file mode 100644 index 0000000000..b2960e29d3 --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/TipParametersDAO.java @@ -0,0 +1,67 @@ +/***************************************************************** + * 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 . + *****************************************************************/ + + +package org.cgiar.ccafs.marlo.data.dao; + +import org.cgiar.ccafs.marlo.data.model.TipParameters; + +import java.util.List; + + +public interface TipParametersDAO { + + /** + * This method removes a specific tipParameters value from the database. + * + * @param tipParametersId is the tipParameters identifier. + * @return true if the tipParameters was successfully deleted, false otherwise. + */ + public void deleteTipParameters(long tipParametersId); + + /** + * This method validate if the tipParameters identify with the given id exists in the system. + * + * @param tipParametersID is a tipParameters identifier. + * @return true if the tipParameters exists, false otherwise. + */ + public boolean existTipParameters(long tipParametersID); + + /** + * This method gets a tipParameters object by a given tipParameters identifier. + * + * @param tipParametersID is the tipParameters identifier. + * @return a TipParameters object. + */ + public TipParameters find(long id); + + /** + * This method gets a list of tipParameters that are active + * + * @return a list from TipParameters null if no exist records + */ + public List findAll(); + + + /** + * This method saves the information of the given tipParameters + * + * @param tipParameters - is the tipParameters object with the new information to be added/updated. + * @return a number greater than 0 representing the new ID assigned by the database, 0 if the tipParameters was + * updated + * or -1 is some error occurred. + */ + public TipParameters save(TipParameters tipParameters); +} diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java new file mode 100644 index 0000000000..f2ebb8bcdd --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java @@ -0,0 +1,84 @@ +/***************************************************************** + * 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 . + *****************************************************************/ + + +package org.cgiar.ccafs.marlo.data.dao.mysql; + +import org.cgiar.ccafs.marlo.data.dao.TipParametersDAO; +import org.cgiar.ccafs.marlo.data.model.TipParameters; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.hibernate.SessionFactory; + +@Named +public class TipParametersMySQLDAO extends AbstractMarloDAO implements TipParametersDAO { + + + @Inject + public TipParametersMySQLDAO(SessionFactory sessionFactory) { + super(sessionFactory); + } + + @Override + public void deleteTipParameters(long tipParametersId) { + TipParameters tipParameters = this.find(tipParametersId); + this.delete(tipParameters); + } + + @Override + public boolean existTipParameters(long tipParametersID) { + TipParameters tipParameters = this.find(tipParametersID); + if (tipParameters == null) { + return false; + } + return true; + + } + + @Override + public TipParameters find(long id) { + return super.find(TipParameters.class, id); + + } + + @Override + public List findAll() { + String query = "from " + TipParameters.class.getName() + " where is_active=1"; + List list = super.findAll(query); + if (list.size() > 0) { + return list; + } + return null; + + } + + @Override + public TipParameters save(TipParameters tipParameters) { + if (tipParameters.getId() == null) { + super.saveEntity(tipParameters); + } else { + tipParameters = super.update(tipParameters); + } + + + return tipParameters; + } + + +} \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/TipParametersManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/TipParametersManager.java new file mode 100644 index 0000000000..fd658fed8a --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/TipParametersManager.java @@ -0,0 +1,74 @@ +/***************************************************************** + * 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 . + *****************************************************************/ +package org.cgiar.ccafs.marlo.data.manager; + +import org.cgiar.ccafs.marlo.data.model.TipParameters; + +import java.util.List; + + +/** + * @author CCAFS + */ + +public interface TipParametersManager { + + + /** + * This method removes a specific tipParameters value from the database. + * + * @param tipParametersId is the tipParameters identifier. + * @return true if the tipParameters was successfully deleted, false otherwise. + */ + public void deleteTipParameters(long tipParametersId); + + + /** + * This method validate if the tipParameters identify with the given id exists in the system. + * + * @param tipParametersID is a tipParameters identifier. + * @return true if the tipParameters exists, false otherwise. + */ + public boolean existTipParameters(long tipParametersID); + + + /** + * This method gets a list of tipParameters that are active + * + * @return a list from TipParameters null if no exist records + */ + public List findAll(); + + + /** + * This method gets a tipParameters object by a given tipParameters identifier. + * + * @param tipParametersID is the tipParameters identifier. + * @return a TipParameters object. + */ + public TipParameters getTipParametersById(long tipParametersID); + + /** + * This method saves the information of the given tipParameters + * + * @param tipParameters - is the tipParameters object with the new information to be added/updated. + * @return a number greater than 0 representing the new ID assigned by the database, 0 if the tipParameters was + * updated + * or -1 is some error occurred. + */ + public TipParameters saveTipParameters(TipParameters tipParameters); + + +} diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/TipParametersManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/TipParametersManagerImpl.java new file mode 100644 index 0000000000..7912fae5e5 --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/TipParametersManagerImpl.java @@ -0,0 +1,77 @@ +/***************************************************************** + * 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 . + *****************************************************************/ +package org.cgiar.ccafs.marlo.data.manager.impl; + + +import org.cgiar.ccafs.marlo.data.dao.TipParametersDAO; +import org.cgiar.ccafs.marlo.data.manager.TipParametersManager; +import org.cgiar.ccafs.marlo.data.model.TipParameters; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +/** + * @author CCAFS + */ +@Named +public class TipParametersManagerImpl implements TipParametersManager { + + + private TipParametersDAO tipParametersDAO; + // Managers + + + @Inject + public TipParametersManagerImpl(TipParametersDAO tipParametersDAO) { + this.tipParametersDAO = tipParametersDAO; + + + } + + @Override + public void deleteTipParameters(long tipParametersId) { + + tipParametersDAO.deleteTipParameters(tipParametersId); + } + + @Override + public boolean existTipParameters(long tipParametersID) { + + return tipParametersDAO.existTipParameters(tipParametersID); + } + + @Override + public List findAll() { + + return tipParametersDAO.findAll(); + + } + + @Override + public TipParameters getTipParametersById(long tipParametersID) { + + return tipParametersDAO.find(tipParametersID); + } + + @Override + public TipParameters saveTipParameters(TipParameters tipParameters) { + + return tipParametersDAO.save(tipParameters); + } + + +} diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java new file mode 100644 index 0000000000..5bf31598a8 --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java @@ -0,0 +1,128 @@ +/***************************************************************** + * 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 . + *****************************************************************/ + +package org.cgiar.ccafs.marlo.data.model; + +import org.cgiar.ccafs.marlo.data.IAuditLog; + +import java.util.Date; + +import com.google.gson.annotations.Expose; + +public class TipParameters extends MarloBaseEntity implements java.io.Serializable, IAuditLog { + + private static final long serialVersionUID = -963914989396761020L; + + @Expose + private String tipTokenService; + @Expose + private String tipLoginService; + @Expose + private String tipStatusService; + @Expose + private String tokenValue; + @Expose + private String privateKey; + @Expose + private String tipBaseUrl; + @Expose + private Date tokenDueDate; + + @Override + public String getLogDeatil() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getModificationJustification() { + // TODO Auto-generated method stub + return null; + } + + @Override + public User getModifiedBy() { + // TODO Auto-generated method stub + return null; + } + + public String getPrivateKey() { + return privateKey; + } + + public String getTipBaseUrl() { + return tipBaseUrl; + } + + public String getTipLoginService() { + return tipLoginService; + } + + public String getTipStatusService() { + return tipStatusService; + } + + public String getTipTokenService() { + return tipTokenService; + } + + public Date getTokenDueDate() { + return tokenDueDate; + } + + public String getTokenValue() { + return tokenValue; + } + + @Override + public boolean isActive() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setModifiedBy(User modifiedBy) { + // TODO Auto-generated method stub + } + + public void setPrivateKey(String privateKey) { + this.privateKey = privateKey; + } + + public void setTipBaseUrl(String tipBaseUrl) { + this.tipBaseUrl = tipBaseUrl; + } + + public void setTipLoginService(String tipLoginService) { + this.tipLoginService = tipLoginService; + } + + + public void setTipStatusService(String tipStatusService) { + this.tipStatusService = tipStatusService; + } + + public void setTipTokenService(String tipTokenService) { + this.tipTokenService = tipTokenService; + } + + public void setTokenDueDate(Date tokenDueDate) { + this.tokenDueDate = tokenDueDate; + } + + public void setTokenValue(String tokenValue) { + this.tokenValue = tokenValue; + } +} \ No newline at end of file diff --git a/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml b/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml new file mode 100644 index 0000000000..6338842e4f --- /dev/null +++ b/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c58e0144fb7a764a89075068bac9561d0d97d716 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Wed, 6 Mar 2024 12:26:01 -0500 Subject: [PATCH 5/6] :sparkles: feat(TIP integration): Create tip management module --- .../data/dao/mysql/TipParametersMySQLDAO.java | 9 +- .../ccafs/marlo/data/model/TipParameters.java | 3 +- .../src/main/resources/hibernate.cfg.xml | 1 + .../main/resources/xmls/TipParameters.hbm.xml | 2 +- .../superadmin/TipGetTokenServiceAction.java | 145 ++++++++++++++++++ .../superadmin/TIPManagementAction.java | 118 ++++++++++++++ .../main/resources/custom/aicrra.properties | 13 ++ .../src/main/resources/global.properties | 13 ++ marlo-web/src/main/resources/struts-json.xml | 8 + .../src/main/resources/struts-superadmin.xml | 9 ++ .../views/superadmin/menu-superadmin.ftl | 1 + .../global/views/superadmin/tipManagement.ftl | 85 ++++++++++ .../global/js/superadmin/tipManagement.js | 26 ++++ 13 files changed, 423 insertions(+), 10 deletions(-) create mode 100644 marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java create mode 100644 marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/superadmin/TIPManagementAction.java create mode 100644 marlo-web/src/main/webapp/WEB-INF/global/views/superadmin/tipManagement.ftl create mode 100644 marlo-web/src/main/webapp/global/js/superadmin/tipManagement.js diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java index f2ebb8bcdd..8cdca3af12 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/TipParametersMySQLDAO.java @@ -29,7 +29,6 @@ @Named public class TipParametersMySQLDAO extends AbstractMarloDAO implements TipParametersDAO { - @Inject public TipParametersMySQLDAO(SessionFactory sessionFactory) { super(sessionFactory); @@ -48,7 +47,6 @@ public boolean existTipParameters(long tipParametersID) { return false; } return true; - } @Override @@ -59,13 +57,12 @@ public TipParameters find(long id) { @Override public List findAll() { - String query = "from " + TipParameters.class.getName() + " where is_active=1"; + String query = "from " + TipParameters.class.getName(); List list = super.findAll(query); if (list.size() > 0) { return list; } return null; - } @Override @@ -75,10 +72,6 @@ public TipParameters save(TipParameters tipParameters) { } else { tipParameters = super.update(tipParameters); } - - return tipParameters; } - - } \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java index 5bf31598a8..1d88399ba6 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/TipParameters.java @@ -86,6 +86,7 @@ public String getTokenValue() { return tokenValue; } + @Override public boolean isActive() { // TODO Auto-generated method stub @@ -95,6 +96,7 @@ public boolean isActive() { @Override public void setModifiedBy(User modifiedBy) { // TODO Auto-generated method stub + } public void setPrivateKey(String privateKey) { @@ -109,7 +111,6 @@ public void setTipLoginService(String tipLoginService) { this.tipLoginService = tipLoginService; } - public void setTipStatusService(String tipStatusService) { this.tipStatusService = tipStatusService; } diff --git a/marlo-data/src/main/resources/hibernate.cfg.xml b/marlo-data/src/main/resources/hibernate.cfg.xml index 0e11e5f8a7..e2d95da5b0 100644 --- a/marlo-data/src/main/resources/hibernate.cfg.xml +++ b/marlo-data/src/main/resources/hibernate.cfg.xml @@ -434,6 +434,7 @@ + diff --git a/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml b/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml index 6338842e4f..01b56b2908 100644 --- a/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml +++ b/marlo-data/src/main/resources/xmls/TipParameters.hbm.xml @@ -15,7 +15,7 @@ - + diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java new file mode 100644 index 0000000000..fd506765eb --- /dev/null +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java @@ -0,0 +1,145 @@ +package org.cgiar.ccafs.marlo.action.json.superadmin; + + +import org.cgiar.ccafs.marlo.action.BaseAction; +import org.cgiar.ccafs.marlo.data.manager.TipParametersManager; +import org.cgiar.ccafs.marlo.data.model.TipParameters; +import org.cgiar.ccafs.marlo.utils.APConfig; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.inject.Inject; + +import com.ibm.icu.text.SimpleDateFormat; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TipGetTokenServiceAction extends BaseAction { + + private static final long serialVersionUID = 3229622720197560976L; + private static final Logger LOG = LoggerFactory.getLogger(TipGetTokenServiceAction.class); + + // Managers + TipParametersManager tipParametersManager; + + // Paramters + String token; + + // Front-end + private String url; + + @Inject + public TipGetTokenServiceAction(APConfig config, TipParametersManager tipParametersManager) { + super(config); + this.tipParametersManager = tipParametersManager; + } + + @Override + public String execute() throws Exception { + + try { + TipParameters tipParameters = new TipParameters(); + + // URL of the first service + List tipParametesList = new ArrayList<>(); + tipParametesList = tipParametersManager.findAll(); + String serviceUrl = null; + String privateKey = null; + if (tipParametesList != null && !tipParametesList.isEmpty() && tipParametesList.get(0) != null + && tipParametesList.get(0).getTipTokenService() != null && tipParametesList.get(0).getPrivateKey() != null) { + + tipParameters = tipParametesList.get(0); + serviceUrl = tipParameters.getTipTokenService(); + privateKey = tipParametesList.get(0).getPrivateKey(); + + URL url = new URL(serviceUrl); + + // Create connection + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Accept", "application/json"); + connection.setDoOutput(true); + + String requestBody = "{private_key:" + privateKey + "}"; + + // Get the output stream to send data + try (OutputStream os = connection.getOutputStream()) { + byte[] input = requestBody.getBytes(StandardCharsets.UTF_8); + os.write(input, 0, input.length); + } + + // Get response + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder response = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + + // Process JSON + JSONObject jsonResponse = new JSONObject(response.toString()); + int status = jsonResponse.getInt("status"); + if (status == 200) { + token = jsonResponse.getString("token"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + Date dueDate = dateFormat.parse(jsonResponse.getString("due_date")); + + // Save token in DB + if (token != null && !token.isEmpty()) { + tipParameters.setTokenValue(token); + } + if (dueDate != null) { + tipParameters.setTokenDueDate(dueDate); + } + tipParametersManager.saveTipParameters(tipParameters); + + return SUCCESS; + } else { + System.out.println("Error: Unexpected status"); + return ERROR; + } + + } else { + return ERROR; + } + } catch (Exception e) { + e.printStackTrace(); + return ERROR; + } + } + + public String getToken() { + return token; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public void prepare() throws Exception { + } + + + public void setToken(String token) { + this.token = token; + } + + @Override + public void setUrl(String url) { + this.url = url; + } +} diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/superadmin/TIPManagementAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/superadmin/TIPManagementAction.java new file mode 100644 index 0000000000..27cc831365 --- /dev/null +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/superadmin/TIPManagementAction.java @@ -0,0 +1,118 @@ +/* + * 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. + *****************************************************************/ + +package org.cgiar.ccafs.marlo.action.superadmin; + +import org.cgiar.ccafs.marlo.action.BaseAction; +import org.cgiar.ccafs.marlo.data.manager.TipParametersManager; +import org.cgiar.ccafs.marlo.data.model.TipParameters; +import org.cgiar.ccafs.marlo.utils.APConfig; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.inject.Inject; + +import org.jfree.util.Log; + + +public class TIPManagementAction extends BaseAction { + + private static final long serialVersionUID = -793652591843623397L; + private TipParametersManager tipParameterManager; + private TipParameters tipParameter; + + @Inject + public TIPManagementAction(APConfig config, TipParametersManager tipParameterManager) { + super(config); + this.tipParameterManager = tipParameterManager; + } + + public TipParameters getTipParameter() { + return tipParameter; + } + + @Override + public void prepare() throws Exception { + try { + tipParameter = tipParameterManager.findAll().get(0); + } catch (Exception e) { + Log.error("error getting tip parameters " + e); + } + } + + @Override + public String save() { + if (this.canAccessSuperAdmin()) { + if (tipParameter != null) { + + TipParameters tipParameterSave = new TipParameters(); + if (tipParameter.getId() != null) { + tipParameterSave.setId(tipParameter.getId()); + } + if (tipParameter.getTipBaseUrl() != null) { + tipParameterSave.setTipBaseUrl(tipParameter.getTipBaseUrl()); + } + if (tipParameter.getTipLoginService() != null) { + tipParameterSave.setTipLoginService(tipParameter.getTipLoginService()); + } + if (tipParameter.getTipStatusService() != null) { + tipParameterSave.setTipStatusService(tipParameter.getTipStatusService()); + } + if (tipParameter.getTipTokenService() != null) { + tipParameterSave.setTipTokenService(tipParameter.getTipTokenService()); + } + if (tipParameter.getTokenDueDate() != null) { + tipParameterSave.setTokenDueDate(tipParameter.getTokenDueDate()); + } + if (tipParameter.getTokenValue() != null) { + tipParameterSave.setTokenValue(tipParameter.getTokenValue()); + } + if (tipParameter.getPrivateKey() != null) { + tipParameterSave.setPrivateKey(tipParameter.getPrivateKey()); + } + + tipParameterManager.saveTipParameters(tipParameterSave); + + } + + if (this.getUrl() == null || this.getUrl().isEmpty()) { + Collection messages = this.getActionMessages(); + if (this.getInvalidFields() != null && !this.getInvalidFields().isEmpty()) { + this.setActionMessages(null); + // this.addActionMessage(Map.toString(this.getInvalidFields().toArray())); + List keys = new ArrayList(this.getInvalidFields().keySet()); + for (String key : keys) { + this.addActionMessage(key + ": " + this.getInvalidFields().get(key)); + } + } else { + this.addActionMessage("message:" + this.getText("saving.saved")); + } + return SUCCESS; + } else { + this.addActionMessage(""); + this.setActionMessages(null); + return REDIRECT; + } + + } else { + return NOT_AUTHORIZED; + } + } + + public void setTipParameter(TipParameters tipParameter) { + this.tipParameter = tipParameter; + } + +} \ No newline at end of file diff --git a/marlo-web/src/main/resources/custom/aicrra.properties b/marlo-web/src/main/resources/custom/aicrra.properties index 39d7874c77..96558d7a44 100644 --- a/marlo-web/src/main/resources/custom/aicrra.properties +++ b/marlo-web/src/main/resources/custom/aicrra.properties @@ -238,6 +238,7 @@ menu.superadmin.institutions=Request Institutions menu.superadmin.customLocations=Locations menu.superadmin.emails=Emails on track menu.superadmin.guestUserMessage=Currently not available to assign 'Guest' roles to existing users +menu.superadmin.tipManagement=TIP Management menu.synthesis=Synthesis menu.synthesis.crpIndicators=PTF Indicators menu.synthesis.outcomeSynthesis=Outcome Synthesis @@ -332,6 +333,7 @@ breadCrumb.menu.feedbackManagement=Feedback Management breadCrumb.menu.buttonGuideManagement=Button Guide Management breadCrumb.menu.messageManagement=MARLO Message Management breadCrumb.menu.shfrmManagement=Soil Health and Fertility Road Map +breadCrumb.menu.tipManagement=TIP Management # Message section message.title=MARLO Message Management @@ -5324,6 +5326,17 @@ deliverable.message=If you need to disseminate your deliverable, please download summaries.board.report.progressSummary.narrative=This report pulls out the information given to the different progress questions on each cluster. Also, you can download the consolidated version for all cluster information. summaries.board.report.progressSummary.title=Brief Summary +# TIP Management +tipParameterManagement.title=TIP Management +tipParameter.privateKey=Private Key +tipParameter.tipTokenService=Token Service Endpoint +tipParameter.tipLoginService=Login Service Endpoint +tipParameter.tipBaseUrl=Base URL +tipParameter.tipStatusService= Status Service Endpoint +tipParameter.tokenValue= Token Value +tipParameter.updateToken= Update Token +tipParameter.tokenDueDate= Token Due Date + #pop-up guide login.popup.title=Login home.popup.title=HomePage diff --git a/marlo-web/src/main/resources/global.properties b/marlo-web/src/main/resources/global.properties index b5e8e367ea..3c07c54c54 100644 --- a/marlo-web/src/main/resources/global.properties +++ b/marlo-web/src/main/resources/global.properties @@ -241,6 +241,7 @@ menu.superadmin.institutions=Request Institutions menu.superadmin.customLocations=Locations menu.superadmin.emails=Emails on track menu.superadmin.guestUserMessage=Currently not available to assign 'Guest' roles to existing users +menu.superadmin.tipManagement=TIP Management menu.synthesis=Synthesis menu.synthesis.crpIndicators=CRP Indicators menu.synthesis.outcomeSynthesis=Outcome Synthesis @@ -335,6 +336,7 @@ breadCrumb.menu.feedbackManagement=Feedback Management breadCrumb.menu.buttonGuideManagement=Button Guide Management breadCrumb.menu.messageManagement=MARLO Message Management breadCrumb.menu.shfrmManagement=Soil Health and Fertility Road Map +breadCrumb.menu.tipManagement=TIP Management # Message section message.title=MARLO Message Management @@ -5448,6 +5450,17 @@ feedbackManagement.parentFieldDescription=Parent Field Description feedbackManagement.title=Feedback Management form.buttons.addFeedbackField=Add feedback field +# TIP Management +tipParameterManagement.title=TIP Management +tipParameter.privateKey=Private Key +tipParameter.tipTokenService=Token Service Endpoint +tipParameter.tipLoginService=Login Service Endpoint +tipParameter.tipBaseUrl=Base URL +tipParameter.tipStatusService= Status Service Endpoint +tipParameter.tokenValue= Token Value +tipParameter.updateToken= Update Token +tipParameter.tokenDueDate= Token Due Date + # Timeline Management timelineManagement.help=Please note that activities are displayed on the homepage timeline component in the order they are entered or in the order defined by the order field, if its filled. By default, the dates of the activities do not determine their order. diff --git a/marlo-web/src/main/resources/struts-json.xml b/marlo-web/src/main/resources/struts-json.xml index dfc5091ee2..9f7888df7e 100644 --- a/marlo-web/src/main/resources/struts-json.xml +++ b/marlo-web/src/main/resources/struts-json.xml @@ -1235,6 +1235,14 @@ true + + + + true + true + + diff --git a/marlo-web/src/main/resources/struts-superadmin.xml b/marlo-web/src/main/resources/struts-superadmin.xml index e4dc783b81..e7a849b247 100644 --- a/marlo-web/src/main/resources/struts-superadmin.xml +++ b/marlo-web/src/main/resources/struts-superadmin.xml @@ -263,6 +263,15 @@ true + + + /WEB-INF/global/views/superadmin/tipManagement.ftl + + tipManagement + true + + + +
+ [#include "/WEB-INF/global/pages/breadcrumb.ftl" /] +
+[#include "/WEB-INF/global/pages/generalMessages.ftl" /] + + +
+
+
+
+ [#include "/WEB-INF/global/views/superadmin/menu-superadmin.ftl" /] +
+
+ [@s.form action=actionName enctype="multipart/form-data" ] + + [#-- System Level Outcomes --] +

[@s.text name="tipParameterManagement.title" /]

+ +
+
+ [@customForm.input name="tipParameter.tipBaseUrl" i18nkey="tipParameter.tipBaseUrl" className="description limitWords-100" required=true /] +
+
+ [@customForm.input name="tipParameter.privateKey" i18nkey="tipParameter.privateKey" className="description limitWords-100" required=true /] +
+
+
+ [@customForm.input name="tipParameter.tipTokenService" i18nkey="tipParameter.tipTokenService" className="description limitWords-100" required=true /] +
+
+
+ [@customForm.input name="tipParameter.tipLoginService" i18nkey="tipParameter.tipLoginService" className="description limitWords-100" required=true /] +
+
+
+ [@customForm.input name="tipParameter.tipStatusService" i18nkey="tipParameter.tipStatusService" className="description limitWords-100" required=true /] +
+
+
+ [@customForm.input id="tipParameter.tokenValue" name="tipParameter.tokenValue" i18nkey="tipParameter.tokenValue" className="description limitWords-100" required=true /] + [@s.text name="tipParameter.updateToken" /] +
+
+
+ [@customForm.input name="tipParameter.tokenDueDate" i18nkey="tipParameter.tokenDueDate" className="description limitWords-100" required=false editable=false /] +
+
+
+ + + [#-- Section Buttons--] +
+
+ [@s.submit type="button" name="save" cssClass="button-save"] [@s.text name="form.buttons.save" /][/@s.submit] +
+
+ + [/@s.form] + +
+
+
+
+ + +[#include "/WEB-INF/global/pages/footer.ftl" /] \ No newline at end of file diff --git a/marlo-web/src/main/webapp/global/js/superadmin/tipManagement.js b/marlo-web/src/main/webapp/global/js/superadmin/tipManagement.js new file mode 100644 index 0000000000..570a88f97f --- /dev/null +++ b/marlo-web/src/main/webapp/global/js/superadmin/tipManagement.js @@ -0,0 +1,26 @@ +$(init); + +function init(){ + updateTipToken(); +} + +function updateTipToken() { + $("#updateTokenBtn").on("click", function(event) { + console.log(baseURL); + $.ajax({ + url: baseURL + '/tipTokenService.do', + type: 'POST', + dataType: 'json', + success: function(response) { + console.log(response); + var token = response.token; + $("#tipParameter.tokenValue").val(token); + $('input[name="tipParameter.tokenValue"]').val(token); + }, + error: function(error) { + console.error('Error getting embedded URL:', error); + } + }); + }); + +} \ No newline at end of file From 459c5bed5f97ce2e23afd220756abb60be44dc59 Mon Sep 17 00:00:00 2001 From: Kenji Tanaka Date: Wed, 6 Mar 2024 14:39:47 -0500 Subject: [PATCH 6/6] :sparkles: feat(TIP integration): Create tip embedded module --- .../tip/TipDinamicUrlGenerationAction.java | 105 ++++++++++++++++++ .../marlo/action/tip/TIPEmbeddedAction.java | 81 ++++++++++++++ .../main/resources/custom/aicrra.properties | 1 + .../src/main/resources/global.properties | 1 + marlo-web/src/main/resources/struts-json.xml | 8 ++ marlo-web/src/main/resources/struts-tip.xml | 20 ++++ marlo-web/src/main/resources/struts.xml | 1 + .../WEB-INF/crp/views/tip/tipEmbedded.ftl | 28 +++++ .../webapp/WEB-INF/global/pages/main-menu.ftl | 30 ++--- .../main/webapp/crp/css/tip/tipEmbedded.css | 13 +++ .../src/main/webapp/crp/js/tip/tipEmbedded.js | 84 ++++++++++++++ 11 files changed, 358 insertions(+), 14 deletions(-) create mode 100644 marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java create mode 100644 marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/tip/TIPEmbeddedAction.java create mode 100644 marlo-web/src/main/resources/struts-tip.xml create mode 100644 marlo-web/src/main/webapp/WEB-INF/crp/views/tip/tipEmbedded.ftl create mode 100644 marlo-web/src/main/webapp/crp/css/tip/tipEmbedded.css create mode 100644 marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java new file mode 100644 index 0000000000..0e7ad618c3 --- /dev/null +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java @@ -0,0 +1,105 @@ +/***************************************************************** + * 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 . + *****************************************************************/ + +package org.cgiar.ccafs.marlo.action.json.tip; + +import org.cgiar.ccafs.marlo.action.BaseAction; +import org.cgiar.ccafs.marlo.data.manager.TipParametersManager; +import org.cgiar.ccafs.marlo.data.model.TipParameters; + +import java.util.List; + +import javax.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TipDinamicUrlGenerationAction extends BaseAction { + + private static final long serialVersionUID = 3229622720197560976L; + private static final Logger LOG = LoggerFactory.getLogger(TipDinamicUrlGenerationAction.class); + + // Front-end + private String dinamicTipURL; + + @Inject + private TipParametersManager tipParametersManager; + + @Inject + public TipDinamicUrlGenerationAction() { + + } + + public String createDinamicURL() { + String tipURL = null; + boolean isCGIARUser = true; + + try { + String userEmail = "", token = "", loginService = ""; + if (this.getCurrentUser() != null && this.getCurrentUser().getEmail() != null) { + userEmail = this.getCurrentUser().getEmail(); + if (this.getCurrentUser().isCgiarUser() == true) { + isCGIARUser = true; + } else { + isCGIARUser = false; + } + } + + List tipParameters = tipParametersManager.findAll(); + if (isCGIARUser) { + if (tipParameters != null && !tipParameters.isEmpty() && tipParameters.get(0) != null) { + if (tipParameters.get(0).getTipTokenService() != null) { + token = tipParameters.get(0).getTokenValue(); + } + if (tipParameters.get(0).getTipLoginService() != null) { + loginService = tipParameters.get(0).getTipLoginService(); + } + } + tipURL = loginService + "/" + token + "/staff/" + userEmail; + } else { + // Not CGIAR User + if (tipParameters != null && tipParameters.get(0) != null && tipParameters.get(0).getTipBaseUrl() != null) { + tipURL = tipParameters.get(0).getTipBaseUrl(); + } + } + } catch (NumberFormatException e) { + LOG.error("Error getting tip URL: " + e); + } + + return tipURL; + } + + @Override + public String execute() throws Exception { + + if (this.createDinamicURL() != null) { + this.dinamicTipURL = this.createDinamicURL(); + return SUCCESS; + } + return ERROR; + } + + public String getDinamicTipURL() { + return dinamicTipURL; + } + + @Override + public void prepare() throws Exception { + } + + public void setDinamicTipURL(String dinamicTipURL) { + this.dinamicTipURL = dinamicTipURL; + } +} \ No newline at end of file diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/tip/TIPEmbeddedAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/tip/TIPEmbeddedAction.java new file mode 100644 index 0000000000..ad33791dd3 --- /dev/null +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/tip/TIPEmbeddedAction.java @@ -0,0 +1,81 @@ +/***************************************************************** + * 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 . + *****************************************************************/ + +package org.cgiar.ccafs.marlo.action.tip; + +import org.cgiar.ccafs.marlo.action.BaseAction; +import org.cgiar.ccafs.marlo.data.manager.BiParametersManager; +import org.cgiar.ccafs.marlo.data.manager.BiReportsManager; +import org.cgiar.ccafs.marlo.data.model.BiParameters; +import org.cgiar.ccafs.marlo.data.model.BiReports; +import org.cgiar.ccafs.marlo.utils.APConfig; + +import java.util.List; + +import javax.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TIPEmbeddedAction extends BaseAction { + + private static final long serialVersionUID = 1329042468240291639L; + + private static final Logger LOG = LoggerFactory.getLogger(TIPEmbeddedAction.class); + + // Managers + private BiReportsManager biReportsManager; + private BiParametersManager biParametersManager; + + // Front-end + private List biReports; + private List biParameters; + + @Inject + public TIPEmbeddedAction(APConfig config, BiReportsManager biReportsManager, + BiParametersManager biParametersManager) { + super(config); + this.biReportsManager = biReportsManager; + this.biParametersManager = biParametersManager; + } + + public List getBiParameters() { + return biParameters; + } + + + public List getBiReports() { + return biReports; + } + + + @Override + public void prepare() { + biReports = biReportsManager.findAll(); + biParameters = biParametersManager.findAll(); + } + + + public void setBiParameters(List biParameters) { + this.biParameters = biParameters; + } + + + public void setBiReports(List biReports) { + this.biReports = biReports; + } + + +} diff --git a/marlo-web/src/main/resources/custom/aicrra.properties b/marlo-web/src/main/resources/custom/aicrra.properties index 96558d7a44..bc3abec4e2 100644 --- a/marlo-web/src/main/resources/custom/aicrra.properties +++ b/marlo-web/src/main/resources/custom/aicrra.properties @@ -255,6 +255,7 @@ menu.additionalReporting.help=Supplementary Reporting not directly linked to a C menu.studies=OICRs & MELIAs menu.bi=BI menu.bi.deliverablesMonitoring=Deliverables Monitoring +menu.tip=Dissemination # Breadcrumb breadCrumb.menu.guestUsers=Guest Users diff --git a/marlo-web/src/main/resources/global.properties b/marlo-web/src/main/resources/global.properties index 3c07c54c54..4d1f743647 100644 --- a/marlo-web/src/main/resources/global.properties +++ b/marlo-web/src/main/resources/global.properties @@ -257,6 +257,7 @@ menu.additionalReporting=Supplementary menu.additionalReporting.help=Supplementary Reporting not directly linked to a Project menu.studies=Evidences menu.bi=BI +menu.tip=Dissemination # Breadcrumb breadCrumb.menu.guestUsers=Guest Users diff --git a/marlo-web/src/main/resources/struts-json.xml b/marlo-web/src/main/resources/struts-json.xml index 9f7888df7e..c457ba9315 100644 --- a/marlo-web/src/main/resources/struts-json.xml +++ b/marlo-web/src/main/resources/struts-json.xml @@ -1198,6 +1198,14 @@ true
+ + + + true + true + + diff --git a/marlo-web/src/main/resources/struts-tip.xml b/marlo-web/src/main/resources/struts-tip.xml new file mode 100644 index 0000000000..069059e441 --- /dev/null +++ b/marlo-web/src/main/resources/struts-tip.xml @@ -0,0 +1,20 @@ + + + + + + + + + + /WEB-INF/crp/views/tip/tipEmbedded.ftl + + + + + + diff --git a/marlo-web/src/main/resources/struts.xml b/marlo-web/src/main/resources/struts.xml index a25855dc0e..31f0aa9403 100644 --- a/marlo-web/src/main/resources/struts.xml +++ b/marlo-web/src/main/resources/struts.xml @@ -554,6 +554,7 @@ + diff --git a/marlo-web/src/main/webapp/WEB-INF/crp/views/tip/tipEmbedded.ftl b/marlo-web/src/main/webapp/WEB-INF/crp/views/tip/tipEmbedded.ftl new file mode 100644 index 0000000000..3d936e8953 --- /dev/null +++ b/marlo-web/src/main/webapp/WEB-INF/crp/views/tip/tipEmbedded.ftl @@ -0,0 +1,28 @@ +[#ftl] +[#assign title = "TIP" /] +[#assign currentSectionString = "${actionName?replace('/','-')}-phase-${(actualPhase.id)!}" /] +[#assign customJS = ["${baseUrlMedia}/js/tip/tipEmbedded.js?20240306"] /] +[#assign customCSS = [ + "${baseUrl}/crp/css/tip/tipEmbedded.css?20240306", "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" + ] +/] +[#assign currentSection = "tip" /] + +[#include "/WEB-INF/global/pages/header.ftl" /] +[#include "/WEB-INF/global/pages/main-menu.ftl" /] + +[#import "/WEB-INF/global/macros/utils.ftl" as utils /] + +
+

Deliverable Dissemination

+
+ Our main goal is to continuously improve the planning and reporting process for our users in the system. Taking into account the above and working in line with OneCGIAR, we have integrated with the TIP tool of the Alliance, which will allow users to disseminate publications in CGSpace and Harvard Datavers for the AICCRA project collections.
+ With this new tool, we will have a more efficient process when putting our publications online +
+
+
+ +
+
+ +[#include "/WEB-INF/global/pages/footer.ftl"] \ No newline at end of file diff --git a/marlo-web/src/main/webapp/WEB-INF/global/pages/main-menu.ftl b/marlo-web/src/main/webapp/WEB-INF/global/pages/main-menu.ftl index 0734fc2500..5f2f3e6e2c 100644 --- a/marlo-web/src/main/webapp/WEB-INF/global/pages/main-menu.ftl +++ b/marlo-web/src/main/webapp/WEB-INF/global/pages/main-menu.ftl @@ -71,7 +71,9 @@ [#-- SUMMARIES - ALL --] { 'slug': 'summaries', 'name': 'menu.summaries', 'namespace': '/summaries', 'action': '${(crpSession)!}/summaries', 'visible': logged, 'active': true } [#-- BI Module --] - { 'slug': 'bi', 'name': 'menu.bi', 'namespace': '/bi', 'action': '${(crpSession)!}/bi', 'visible': logged && biModuleActive, 'active': true } + { 'slug': 'bi', 'name': 'menu.bi', 'namespace': '/bi', 'action': '${(crpSession)!}/bi', 'visible': logged && biModuleActive, 'active': true }, + [#-- TIP Module --] + { 'slug': 'tip', 'name': 'menu.tip', 'namespace': '/tip', 'action': '${(crpSession)!}/tip', 'visible': logged && action.hasSpecificities('tip_section_active'), 'active': true } ]/] @@ -116,19 +118,19 @@ diff --git a/marlo-web/src/main/webapp/crp/css/tip/tipEmbedded.css b/marlo-web/src/main/webapp/crp/css/tip/tipEmbedded.css new file mode 100644 index 0000000000..b451eb923d --- /dev/null +++ b/marlo-web/src/main/webapp/crp/css/tip/tipEmbedded.css @@ -0,0 +1,13 @@ +.fullscreen-button { + position: absolute; + top: -10x; + right: 17px; +} + +.timeline-phases { + display: none; +} + +.sectionTitle-tip{ + margin-top:10px; +} \ No newline at end of file diff --git a/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js b/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js new file mode 100644 index 0000000000..0d49acec65 --- /dev/null +++ b/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js @@ -0,0 +1,84 @@ +$(document).ready(function() { + var isFullscreen = false; + var iframe = null; + var iframeInitialWidth = '100%'; + var iframeInitialHeight = '800px'; + var fullscreenButton = null; + + $.ajax({ + url: baseURL + '/tipGenerateUrlAction.do', + type: 'GET', + dataType: 'json', + success: function(response) { + + var embeddedPageUrl = response.dinamicTipURL; + console.log("embeddedPageUrl " + embeddedPageUrl); + iframe = document.createElement('iframe'); + iframe.src = embeddedPageUrl; + iframe.style.width = iframeInitialWidth; + iframe.style.height = iframeInitialHeight; + + /****************/ + iframe.setAttribute('allow', 'autoplay'); + iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-top-navigation'); + + // Add iframe to the element with ID 'embeddedPage' + document.getElementById('embeddedPage').appendChild(iframe); + + // Create and add fullscreen button + fullscreenButton = document.createElement('button'); + fullscreenButton.classList.add('fullscreen-button'); + fullscreenButton.innerHTML = ' Fullscreen'; + + fullscreenButton.addEventListener('click', toggleFullscreen); + + // Add button to the 'embeddedPage' container + document.getElementById('embeddedPage').appendChild(fullscreenButton); + }, + error: function(xhr, status, error) { + console.error('Error getting embedded URL:', error); + } + }); + + function toggleFullscreen() { + var elem = document.getElementById('embeddedPage'); + + if (!isFullscreen) { + if (elem.requestFullscreen) { + elem.requestFullscreen(); + } else if (elem.mozRequestFullScreen) { /* Firefox */ + elem.mozRequestFullScreen(); + } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ + elem.webkitRequestFullscreen(); + } else if (elem.msRequestFullscreen) { /* IE/Edge */ + elem.msRequestFullscreen(); + } + } else { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.mozCancelFullScreen) { /* Firefox */ + document.mozCancelFullScreen(); + } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */ + document.webkitExitFullscreen(); + } else if (document.msExitFullscreen) { /* IE/Edge */ + document.msExitFullscreen(); + } + } + } + + // Detect fullscreen change event + document.addEventListener('fullscreenchange', function() { + isFullscreen = !!document.fullscreenElement; + if (isFullscreen) { + iframeInitialWidth = iframe.style.width; // Save initial width + iframeInitialHeight = iframe.style.height; // Save initial height + iframe.style.width = '100vw'; // Take full window width + iframe.style.height = '100vh'; // Take full window height + fullscreenButton.innerHTML = ' Exit Fullscreen'; + } else { + iframe.style.width = iframeInitialWidth; // Revert to initial width + iframe.style.height = iframeInitialHeight; // Revert to initial height + fullscreenButton.innerHTML = ' Fullscreen'; + } + }); +}); \ No newline at end of file