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

112 lines
4.1 KiB
Java

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.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.common.portal.PortalContext;
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 {
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;
}
}