moving-map-portlet/src/main/java/org/gcube/portlets/user/moving/CompileForm.java

136 lines
5.3 KiB
Java
Raw Normal View History

2021-11-02 14:51:10 +01:00
package org.gcube.portlets.user.moving;
import java.io.IOException;
2021-11-03 11:09:23 +01:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
2021-11-02 14:51:10 +01:00
import java.util.ArrayList;
2021-11-03 12:57:27 +01:00
import java.util.Iterator;
2021-11-02 14:51:10 +01:00
import java.util.List;
2021-11-02 18:00:49 +01:00
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
2021-11-02 14:51:10 +01:00
import javax.portlet.PortletException;
2021-11-03 12:57:27 +01:00
import javax.portlet.ProcessAction;
2021-11-02 14:51:10 +01:00
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
2021-11-03 12:57:27 +01:00
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
2021-11-02 14:51:10 +01:00
2021-11-03 11:09:23 +01:00
import org.gcube.common.portal.PortalContext;
2021-11-03 12:57:27 +01:00
import com.liferay.portal.kernel.captcha.CaptchaUtil;
2021-11-02 14:51:10 +01:00
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
/**
* Portlet implementation class ThematicGateways
*/
public class CompileForm extends MVCPortlet {
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(CompileForm.class);
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
2021-11-03 11:09:23 +01:00
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);
}
2021-11-02 14:51:10 +01:00
super.render(renderRequest, renderResponse);
}
2021-11-03 12:57:27 +01:00
public void submittedForm(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String name = actionRequest.getParameter("name");
String surname = actionRequest.getParameter("surname");
String organisation = actionRequest.getParameter("organisation");
String emailAddress = actionRequest.getParameter("emailAddress");
String organisationType = actionRequest.getParameter("organisationType");
String mainMotivation = actionRequest.getParameter("mainMotivation");
String[] itemsAreaOfExpertiseSelectValues = actionRequest.getParameterValues("areaOfExpertiseSelect");
String commitment = actionRequest.getParameter("commitment");
System.out.println("name:" + name);
System.out.println("surname:" + surname);
System.out.println("organisation:" + organisation);
System.out.println("email:" + emailAddress);
System.out.println(organisationType);
System.out.println(mainMotivation);
for (int i = 0; i < itemsAreaOfExpertiseSelectValues.length; i++) {
System.out.println(itemsAreaOfExpertiseSelectValues[i]);
}
System.out.println(commitment);
2021-11-02 18:00:49 +01:00
}
2021-11-02 14:51:10 +01:00
2021-11-03 11:09:23 +01:00
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;
}
2021-11-02 14:51:10 +01:00
2021-11-03 11:09:23 +01:00
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;
}
2021-11-03 12:57:27 +01:00
2021-11-03 11:09:23 +01:00
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;
}
2021-11-03 12:57:27 +01:00
2021-11-02 14:51:10 +01:00
}