UI and DB done

This commit is contained in:
Massimiliano Assante 2021-11-03 11:09:23 +01:00
parent 0d9ceff1a4
commit 1d2533ea3d
8 changed files with 429 additions and 52 deletions

19
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>moving-map-portlet</artifactId>
<packaging>war</packaging>
<name>moving-map-forms Portlets</name>
<name>moving-map-forms Portlets</name>
<version>1.0.0-SNAPSHOT</version>
<description>
Thematic Gateways Portlet
@ -46,11 +46,6 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.infrastructure.detachedres</groupId>
<artifactId>detachedres-library</artifactId>
<version>[1.1.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
@ -61,18 +56,18 @@
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-model</artifactId>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>

View File

@ -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<String> organisation_types = getOrganisationTypes(conn);
List<String> main_motivations = getMainMotivations(conn);
List<String> areas_of_expertise = getAreasOfExpertise(conn);
List<String> 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<String> getOrganisationTypes(Connection conn) throws Exception {
_log.debug("getting organisation_types ");
List<String> 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<String> getMainMotivations(Connection conn) throws Exception {
_log.debug("getting main_motivations ");
List<String> 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<String> getAreasOfExpertise(Connection conn) throws Exception {
_log.debug("getting areas_of_expertise ");
List<String> 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<String> getDgreesOfParticipation(Connection conn) throws Exception {
_log.debug("getting degrees_of_participation ");
List<String> 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;
}
}

View File

@ -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();
}
}

View File

@ -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<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> conf = client.submit(query);
ServiceEndpoint res = conf.get(0);
return res.profile().accessPoints().iterator().next();
}
}

View File

@ -6,6 +6,7 @@
<portlet-name>moving-form-compile</portlet-name>
<icon>/icon.png</icon>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portal-javascript>https://www.google.com/recaptcha/api.js</header-portal-javascript>
<footer-portlet-javascript>
/js/main.js
</footer-portlet-javascript>

View File

@ -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<String> organisation_types = (List<String>) renderRequest.getAttribute("organisation_types");
List<String> main_motivations = (List<String>) renderRequest.getAttribute("main_motivations");
List<String> areas_of_expertise = (List<String>) renderRequest.getAttribute("areas_of_expertise");
List<String> degrees_of_participation = (List<String>) 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);
%>
<portlet:defineObjects />
<portlet:actionURL name="addEntry" var="addEntryURL" />
<aui:form action="<%= addEntryURL %>" method="post" name="myForm">
<aui:input label="My Text Input" name="myTextInput" type="text"
value='<%= "My Text Value" %>' />
<aui:button type="submit" />
<p class="lead">Expression of Interest for the EU Multi-Actor
Platform</p>
<aui:form action="<%=addEntryURL%>" method="post" name="movingForm">
<aui:fieldset>
<aui:input label="Name" name="name" type="text" required="true"
style="width:300px;" />
<aui:input label="Surname" name="surname" type="text" required="true"
style="width:300px;" />
<aui:input label="Organisation" name="organisation" type="text"
required="true" style="width:300px;" />
<aui:select label="Organisation Type" name="organisationType"
required="true" showEmptyOption="true" style="width:800px;">
<c:forEach var="type" items="${organisation_types}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
</aui:select>
<aui:input name="emailAddress" required="true" style="width:300px;">
<aui:validator name="email" />
</aui:input>
<aui:input label="Country" name="country" type="text" required="true"
style="width:300px;" />
</aui:fieldset>
<aui:fieldset>
<aui:input id="participatedInActivities " type="checkbox"
name="participatedInActivities"
label="Have you participated in the activities of any of our MOVING Regional Multi-Actors Platforms?" />
<!--
SELECT
-->
<aui:select
label="What is your main motivation for joining the EU MAP of MOVING?"
name="mainMotivation" required="true" showEmptyOption="true"
style="width:800px;">
<c:forEach var="type" items="${main_motivations}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
</aui:select>
<aui:input
label="Please elaborate on your motivation expressed above so that we understand better your interest, and form a dynamic and relevant community. Vague explanations of the motivation might not be taken into consideration."
name="textareaMotivation" type="textarea" style="width:800px;"
placeholder="Free text 150 words" />
<!--
SELECT Multi areas_of_expertise
-->
<aui:select
label="What is your main area of expertise in relation to mountain sustainability and resilience?"
name="areaOfExpertiseSelect" required="true" style="width:800px;"
multiple="true">
<c:forEach var="type" items="${areas_of_expertise}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
</aui:select>
<!-- String[] items = actionRequest.getParameterValues("areaOfExpertiseSelect"); -->
<aui:input
label="Please elaborate on the relevant experience you can bring to mountain value chains and the resilience of these areas, so that we have more detailed information to be able to form a dynamic and relevant community."
name="textareaExperience" type="textarea" style="width:800px;"
placeholder="Free text 150 words" />
<aui:select
label="As a starting point, the degree of participation you commit to is:"
name="commitment" required="true" showEmptyOption="true"
style="width:800px;">
<c:forEach var="type" items="${degrees_of_participation}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
</aui:select>
<aui:spacer></aui:spacer>
<p class="lead">Data Management</p>
<p>
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
<aui:a href="https://www.moving-h2020.eu/privacy-cookies-policy/"
target="_blank">Privacy Policy</aui:a>
.
</p>
<aui:input id="privacyPolicyAgree" type="checkbox"
name="privacyPolicyAgree" label="I Agree" required="true" />
</aui:fieldset>
<!--
Submit Button
-->
<div style="width: 100%; text-align: center;">
<div class="g-recaptcha"
data-sitekey="6Ld0hfYZAAAAAKlIHde1v3QE4NyY4AniN6j-U9SP"></div>
<br />
<aui:button value="Submit your application" type="submit"
cssClass="btn-large btn-fill" />
</div>
</aui:form>

View File

@ -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"%>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<theme:defineObjects />

View File

@ -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" %>
<portlet:defineObjects />
This is the <b>moving-map-forms</b>.