From 1d2533ea3d8cb5ca5ff0b620ef4708ae3dfe7cb9 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 3 Nov 2021 11:09:23 +0100 Subject: [PATCH] UI and DB done --- pom.xml | 19 ++- .../portlets/user/moving/CompileForm.java | 92 ++++++++++++-- .../portlets/user/moving/DB_Credentials.java | 70 +++++++++++ .../user/moving/DatabaseConnection.java | 102 ++++++++++++++++ src/main/webapp/WEB-INF/liferay-portlet.xml | 1 + .../webapp/html/form-compile/form-map.jsp | 113 ++++++++++++++++-- src/main/webapp/html/init.jsp | 63 ++++++++++ src/main/webapp/view.jsp | 21 ---- 8 files changed, 429 insertions(+), 52 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/moving/DB_Credentials.java create mode 100644 src/main/java/org/gcube/portlets/user/moving/DatabaseConnection.java create mode 100644 src/main/webapp/html/init.jsp delete mode 100644 src/main/webapp/view.jsp diff --git a/pom.xml b/pom.xml index b7bbc79..042a147 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portal moving-map-portlet war - moving-map-forms Portlets + moving-map-forms Portlets 1.0.0-SNAPSHOT Thematic Gateways Portlet @@ -46,11 +46,6 @@ - - org.gcube.infrastructure.detachedres - detachedres-library - [1.1.0-SNAPSHOT, 2.0.0) - org.gcube.dvos usermanagement-core @@ -61,18 +56,18 @@ portal-manager provided + + org.gcube.resources.discovery + ic-client + commons-beanutils commons-beanutils provided - org.gcube.common - storagehub-client-library - - - org.gcube.common - storagehub-model + org.gcube.core + common-encryption com.liferay.portal diff --git a/src/main/java/org/gcube/portlets/user/moving/CompileForm.java b/src/main/java/org/gcube/portlets/user/moving/CompileForm.java index 78619ed..a835c83 100644 --- a/src/main/java/org/gcube/portlets/user/moving/CompileForm.java +++ b/src/main/java/org/gcube/portlets/user/moving/CompileForm.java @@ -1,8 +1,10 @@ package org.gcube.portlets.user.moving; import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import javax.portlet.ActionRequest; @@ -11,15 +13,10 @@ import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; -import org.gcube.vomanagement.usermanagement.model.GCubeGroup; -import org.gcube.vomanagement.usermanagement.model.VirtualGroup; -import org.gcube.vomanagement.usermanagement.util.ManagementUtils; +import org.gcube.common.portal.PortalContext; + import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.model.Group; -import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.util.bridges.mvc.MVCPortlet; /** @@ -30,15 +27,86 @@ public class CompileForm extends MVCPortlet { @Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException { -// renderRequest.setAttribute("theGateways", theGateways); - System.out.println("cao"); + Connection conn = null; + try { + conn = DatabaseConnection.getInstance("/"+PortalContext.getConfiguration().getInfrastructureName()).getConnection(); + } catch (Exception e) { + _log.error("Something wrong with Database connection, name: "+DatabaseConnection.DB_SERVICE_ENDPOINT_NAME); + } + try { + if (conn != null) { + List organisation_types = getOrganisationTypes(conn); + List main_motivations = getMainMotivations(conn); + List areas_of_expertise = getAreasOfExpertise(conn); + List degrees_of_participation = getDgreesOfParticipation(conn); + renderRequest.setAttribute("organisation_types", organisation_types); + renderRequest.setAttribute("main_motivations", main_motivations); + renderRequest.setAttribute("areas_of_expertise", areas_of_expertise); + renderRequest.setAttribute("degrees_of_participation", degrees_of_participation); + } + } catch (Exception e) { + _log.error("Something wrong with Database queries while getting combo types", e); + } super.render(renderRequest, renderResponse); - } - + public void addEntry(ActionRequest request, ActionResponse response) { System.out.println("bao"); } + private static List getOrganisationTypes(Connection conn) throws Exception { + _log.debug("getting organisation_types "); + List toReturn = new ArrayList<>(); + String selectSQL = "SELECT * FROM organisation_types"; + PreparedStatement preparedStatement = conn.prepareStatement(selectSQL); + ResultSet rs = preparedStatement.executeQuery(); + while (rs.next()) { + String toAdd = rs.getString("combo_value"); + _log.debug("Adding organisation_types" + toAdd); + toReturn.add(toAdd); + } + return toReturn; + } + private static List getMainMotivations(Connection conn) throws Exception { + _log.debug("getting main_motivations "); + List toReturn = new ArrayList<>(); + String selectSQL = "SELECT * FROM main_motivations"; + PreparedStatement preparedStatement = conn.prepareStatement(selectSQL); + ResultSet rs = preparedStatement.executeQuery(); + while (rs.next()) { + String toAdd = rs.getString("combo_value"); + _log.debug("Adding main_motivations" + toAdd); + toReturn.add(toAdd); + } + return toReturn; + } + + private static List getAreasOfExpertise(Connection conn) throws Exception { + _log.debug("getting areas_of_expertise "); + List toReturn = new ArrayList<>(); + String selectSQL = "SELECT * FROM areas_of_expertise"; + PreparedStatement preparedStatement = conn.prepareStatement(selectSQL); + ResultSet rs = preparedStatement.executeQuery(); + while (rs.next()) { + String toAdd = rs.getString("combo_value"); + _log.debug("Adding areas_of_expertise" + toAdd); + toReturn.add(toAdd); + } + return toReturn; + } + + private static List getDgreesOfParticipation(Connection conn) throws Exception { + _log.debug("getting degrees_of_participation "); + List toReturn = new ArrayList<>(); + String selectSQL = "SELECT * FROM degrees_of_participation"; + PreparedStatement preparedStatement = conn.prepareStatement(selectSQL); + ResultSet rs = preparedStatement.executeQuery(); + while (rs.next()) { + String toAdd = rs.getString("combo_value"); + _log.debug("Adding degrees_of_participation" + toAdd); + toReturn.add(toAdd); + } + return toReturn; + } } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/moving/DB_Credentials.java b/src/main/java/org/gcube/portlets/user/moving/DB_Credentials.java new file mode 100644 index 0000000..600dbc1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/moving/DB_Credentials.java @@ -0,0 +1,70 @@ +package org.gcube.portlets.user.moving; + +public class DB_Credentials { + + private String DBURL, DBName, user, pwd; + + public DB_Credentials(String DBURL, String DBName, String user, String pwd) { + super(); + this.DBURL = DBURL; + this.DBName = DBName; + this.user = user; + this.pwd = pwd; + } + + public DB_Credentials() { + // TODO Auto-generated constructor stub + } + + public String getJDBCURL() { + return new StringBuilder("jdbc:postgresql://").append(DBURL).append("/").append(DBName).append("?user=").append(this.user).toString(); + } + + public String getDBURL() { + return DBURL; + } + + public void setDBURL(String dBURL) { + DBURL = dBURL; + } + + public String getDBName() { + return DBName; + } + + public void setDBName(String dBName) { + DBName = dBName; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DB_Credentials [DBURL="); + builder.append(DBURL); + builder.append(", DBName="); + builder.append(DBName); + builder.append(", user="); + builder.append(user); + builder.append(", pwd="); + builder.append(pwd); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/moving/DatabaseConnection.java b/src/main/java/org/gcube/portlets/user/moving/DatabaseConnection.java new file mode 100644 index 0000000..194f565 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/moving/DatabaseConnection.java @@ -0,0 +1,102 @@ +package org.gcube.portlets.user.moving; +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.List; + +import org.gcube.common.encryption.encrypter.StringEncrypter; +import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + + +public class DatabaseConnection { + public static final String DB_SERVICE_ENDPOINT_NAME = "MOVING-MAP-Forms"; + public static final String DB_SERVICE_ENDPOINT_CATEGORY = "Database"; + + private static Log _log = LogFactoryUtil.getLog(DatabaseConnection.class); + + private static DatabaseConnection instance; + private Connection connection; + + private DatabaseConnection(DB_Credentials dbparams) throws SQLException { + try { + Class.forName("org.postgresql.Driver"); + this.connection = DriverManager.getConnection(dbparams.getJDBCURL(), dbparams.getUser(), dbparams.getPwd()); + } catch (ClassNotFoundException ex) { + _log.error("Database Connection Creation Failed : " + ex.getMessage()); + } + } + + public Connection getConnection() { + return connection; + } + + public static DatabaseConnection getInstance(String context) throws Exception { + if (instance == null || instance.getConnection().isClosed()) { + DB_Credentials cred = getDBCredentials(context); + + instance = new DatabaseConnection(cred); + _log.info("Database Connection acquired for : " + cred.getJDBCURL()); + } + return instance; + } + /** + * + * @param request + * @param response + * @param instance + * @return the credentails, and if the db is empty created the schema + * @throws Exception + */ + private static DB_Credentials getDBCredentials(String currContext) throws Exception { + AccessPoint ac = getDBAccessPoint(currContext); + DB_Credentials toReturn = new DB_Credentials(); + _log.debug("Got AccessPoint:" + ac.toString()); + String dbAddress = ac.address(); //"localhost:5432"; // + toReturn.setDBURL(dbAddress); + _log.debug("DB address: "+ dbAddress); + String dbName = ac.name(); + toReturn.setDBName(dbName); + _log.debug("DB name: "+ dbName); + String dbUser = ac.username(); + toReturn.setUser(dbUser); + _log.debug("DB user: " + dbUser); + String jdbcURL = new StringBuffer("jdbc:postgresql://").append(dbAddress).append("/").append(dbName).toString(); + _log.debug("jdbc.url: "+jdbcURL); + ScopeProvider.instance.set(currContext); + String pwd = StringEncrypter.getEncrypter().decrypt(ac.password()); + toReturn.setPwd(pwd); + _log.debug("Decrypted Password OK"); + + return toReturn; + } + /** + * Gets the survey DB access point. + * + * @return the survey DB access point + */ + private static AccessPoint getDBAccessPoint(String currContext) { + //set the context for this resource + ScopeProvider.instance.set(currContext); + //construct the xquery + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Name/text() eq '"+ DB_SERVICE_ENDPOINT_NAME +"'"); + query.addCondition("$resource/Profile/Category/text() eq '"+ DB_SERVICE_ENDPOINT_CATEGORY +"'"); + + DiscoveryClient client = clientFor(ServiceEndpoint.class); + List conf = client.submit(query); + ServiceEndpoint res = conf.get(0); + + return res.profile().accessPoints().iterator().next(); + } + +} diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml index ef14f19..7d09247 100644 --- a/src/main/webapp/WEB-INF/liferay-portlet.xml +++ b/src/main/webapp/WEB-INF/liferay-portlet.xml @@ -6,6 +6,7 @@ moving-form-compile /icon.png /css/main.css + https://www.google.com/recaptcha/api.js /js/main.js diff --git a/src/main/webapp/html/form-compile/form-map.jsp b/src/main/webapp/html/form-compile/form-map.jsp index c51ebc7..15fca56 100644 --- a/src/main/webapp/html/form-compile/form-map.jsp +++ b/src/main/webapp/html/form-compile/form-map.jsp @@ -1,12 +1,111 @@ <%@include file="../init.jsp"%> -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> + + +<% +List organisation_types = (List) renderRequest.getAttribute("organisation_types"); +List main_motivations = (List) renderRequest.getAttribute("main_motivations"); +List areas_of_expertise = (List) renderRequest.getAttribute("areas_of_expertise"); +List degrees_of_participation = (List) renderRequest.getAttribute("degrees_of_participation"); + +pageContext.setAttribute("organisation_types", organisation_types); +pageContext.setAttribute("main_motivations", main_motivations); +pageContext.setAttribute("areas_of_expertise", areas_of_expertise); +pageContext.setAttribute("degrees_of_participation", degrees_of_participation); +%> - - - - - +

Expression of Interest for the EU Multi-Actor + Platform

+ + + + + + + + ${type} + + + + + + + + + + + + + ${type} + + + + + + + ${type} + + + + + + + ${type} + + + +

Data Management

+

+ MOVING is responsible for the processing of the personal data + provided with your consent when registering and informs you that the + data provided will be processed in accordance with the General Data + Protection Regulation (EU) 2016/679 of 27 April 2016 (GDPR) and other + applicable rules, for the management of the activity and to send + other electronic communications of content related to it. Read more + in our + Privacy Policy + . +

+ +
+ +
+
+
+ +
diff --git a/src/main/webapp/html/init.jsp b/src/main/webapp/html/init.jsp new file mode 100644 index 0000000..16f7b85 --- /dev/null +++ b/src/main/webapp/html/init.jsp @@ -0,0 +1,63 @@ +<%@page import="com.liferay.portal.model.Layout"%> +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + +<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %> +<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %> +<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %> +<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %> +<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> +<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %> + +<%@page import="com.liferay.util.portlet.PortletRequestUtil"%> +<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%> +<%@ page import="com.liferay.portal.util.PortalUtil" %> +<%@ page import="com.liferay.portal.kernel.util.StringUtil" %> +<%@ page import="com.liferay.portal.kernel.util.Validator"%> +<%@ page import="com.liferay.portal.kernel.util.StringPool" %> +<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %> +<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %> +<%@ page import="com.liferay.portal.kernel.util.ListUtil" %> +<%@ page import="com.liferay.portal.kernel.util.Validator" %> +<%@ page import="com.liferay.portal.kernel.util.WebKeys" %> +<%@ page import="com.liferay.portal.kernel.bean.BeanParamUtil" %> +<%@ page import="com.liferay.portal.kernel.language.LanguageUtil"%> +<%@page import="com.liferay.portal.kernel.util.GetterUtil"%> +<%@ page import="com.liferay.portal.service.permission.PortalPermissionUtil" %> +<%@ page import="com.liferay.portal.service.permission.PortletPermissionUtil" %> +<%@ page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%> +<%@ page import="com.liferay.portal.kernel.portlet.LiferayPortletMode"%> +<%@ page import="javax.portlet.PortletURL" %> +<%@ page import="java.util.List" %> +<%@ page import="java.net.URLEncoder" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.LinkedHashMap" %> +<%@page import="com.liferay.portal.kernel.dao.search.RowChecker"%> +<%@ page import="java.util.Calendar" %> +<%@ page import="java.util.Collections" %> +<%@page import="java.util.Date"%> +<%@page import="java.util.Base64"%> +<%@ page import="java.text.SimpleDateFormat"%> +<%@ page import="java.text.DateFormat"%> +<%@page import="com.liferay.portal.kernel.workflow.WorkflowConstants"%> +<%@page import="com.liferay.portlet.journal.model.JournalArticle"%> +<%@page import="com.liferay.portlet.dynamicdatamapping.model.DDMTemplate"%> +<%@page import="com.liferay.portlet.dynamicdatamapping.model.DDMStructure"%> +<%@page import="com.liferay.portal.security.permission.ActionKeys"%> +<%@page import="javax.portlet.PortletSession"%> +<%@page import="com.liferay.portal.model.Team"%> +<%@page import="com.liferay.portal.model.Group"%> +<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%> +<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%> + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/view.jsp b/src/main/webapp/view.jsp deleted file mode 100644 index 66ed1bd..0000000 --- a/src/main/webapp/view.jsp +++ /dev/null @@ -1,21 +0,0 @@ -<%-- -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library 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 Lesser General Public License for more - * details. - */ ---%> - -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> - - - -This is the moving-map-forms. \ No newline at end of file