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 d3ef626..a32b1b5 100644 --- a/src/main/java/org/gcube/portlets/user/moving/CompileForm.java +++ b/src/main/java/org/gcube/portlets/user/moving/CompileForm.java @@ -47,7 +47,7 @@ import com.liferay.util.bridges.mvc.MVCPortlet; */ public class CompileForm extends MVCPortlet { private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(CompileForm.class); - + private static final String MANAGE_USERS_REQUESTS_FRIENDLY_URL = "/manage-expression-of-interest"; protected static final String MAIL_FROM = "MOVING Gateway "; private static final String MAIL_SUBJECT = "MOVING EU Multi-Actor Platform: email confirmation"; @@ -58,15 +58,15 @@ public class CompileForm extends MVCPortlet { + "\n" + "Best regards,\n" + "MOVING team\n"; - + private static final String MAIL_BODY_VRE_MANAGER = "Dear MOVING EU-MAP Manager,\n" + "A new request to join the MOVING EU-level Multi-Actor Platform (MAP) has been submitted.\n" + "\nPlease manage this request:\n"; - + private String mailServiceHost = "localhost"; private String mailServicePort = "25"; - - + + @Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) { Connection conn = null; @@ -82,7 +82,7 @@ public class CompileForm extends MVCPortlet { renderRequest.setAttribute("main_motivations", main_motivations); renderRequest.setAttribute("areas_of_expertise", areas_of_expertise); renderRequest.setAttribute("degrees_of_participation", degrees_of_participation); - + super.render(renderRequest, renderResponse); } catch (Exception e) { _log.error("Something wrong with Databaseconnection or with queries while getting combo types", e); @@ -96,144 +96,141 @@ public class CompileForm extends MVCPortlet { String organisation = actionRequest.getParameter("organisation"); String organisationType = actionRequest.getParameter("organisationType"); String emailAddress = actionRequest.getParameter("emailAddress"); - + String country = actionRequest.getParameter("country"); String participatedInActivitiesString = (String) actionRequest.getParameter("participatedInActivities"); boolean participatedInActivities = Boolean.parseBoolean(participatedInActivitiesString); String textareaMotivation = actionRequest.getParameter("textareaMotivation"); String elaborated_expertise = actionRequest.getParameter("textareaExperience"); - - + + _log.debug("name:" + name); _log.debug("surname:" + surname); _log.debug("organisation:" + organisation); _log.debug("organisationType:" + organisationType); _log.debug("email:" + emailAddress); _log.debug("country:" + country); - _log.debug("participatedInActivities:" + participatedInActivities); - _log.debug("textareaMotivation:\n" + textareaMotivation+"\n"); - _log.info("itemsAreaOfExpertise (Multi):\n"); - + _log.info("participatedInActivities:" + participatedInActivities); + Connection conn; try { conn = DatabaseConnection.getInstance("/"+PortalContext.getConfiguration().getInfrastructureName()).getConnection(); - + String[] mainMotivationValues = actionRequest.getParameterValues("mainMotivation"); List list = getMainMotivations(conn); String[] main_motivations = list.toArray(new String[0]); String mainMotivation = ""; - + for (int i = 0; i < mainMotivationValues.length; i++) { - System.out.println(i+"mainMotivationValues[i]="+mainMotivationValues[i]); boolean valueTrue = Boolean.parseBoolean(mainMotivationValues[i]); - if (valueTrue) + if (valueTrue && i > 0) mainMotivation += main_motivations[i-1]+"; "; //0 is a placeholder always false } - + System.out.println("mainMotivation="+mainMotivation); - + String[] itemsAreaOfExpertiseSelectValues = actionRequest.getParameterValues("areaOfExpertiseSelect"); list = getAreasOfExpertise(conn); String[] areas_of_expertise = list.toArray(new String[0]); String areaOfExpertise = ""; - + for (int i = 0; i < itemsAreaOfExpertiseSelectValues.length; i++) { boolean valueTrue = Boolean.parseBoolean(itemsAreaOfExpertiseSelectValues[i]); - if (valueTrue) + if (valueTrue && i > 0) areaOfExpertise += areas_of_expertise[i-1]+"; "; } - + System.out.println("areaOfExpertise="+areaOfExpertise); - + String[] degree_of_participationValues = actionRequest.getParameterValues("commitment"); list = getDgreesOfParticipation(conn); String[] degrees_of_participation = list.toArray(new String[0]); - String degree_of_participation = ""; - + String degreeOfParticipation = ""; + for (int i = 0; i < degree_of_participationValues.length; i++) { boolean valueTrue = Boolean.parseBoolean(degree_of_participationValues[i]); - if (valueTrue) - degree_of_participation += degrees_of_participation[i-1]+"; "; //0 is a placeholder always false + if (valueTrue && i > 0) + degreeOfParticipation += degrees_of_participation[i-1]+"; "; //0 is a placeholder always false } - - System.out.println("degree_of_participation="+degree_of_participation); - - - _log.debug("textareaExperience:\n" + elaborated_expertise+"\n"); - _log.info("Got form compiled, inserting in DB."); + System.out.println("degree_of_participation="+degreeOfParticipation); + + + _log.debug("textareaExperience:\n" + elaborated_expertise+"\n"); + + _log.info("Got form compiled, inserting in DB."); + + String insertTableSQL = "INSERT INTO forms(name, surname, organisation, organisation_type, email, " + + "country, activities_participation, main_motivation, elaborated_motivation, area_of_expertise, " + + "elaborated_expertise, degree_of_participation, data_management, datecreated, processed_form, user_accepted) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,current_timestamp,?,?)"; + + PreparedStatement preparedStatement = conn.prepareStatement(insertTableSQL); + preparedStatement.setString(1, name); + preparedStatement.setString(2, surname); + preparedStatement.setString(3, organisation); + preparedStatement.setString(4, organisationType); + preparedStatement.setString(5, emailAddress); + preparedStatement.setString(6, country); + preparedStatement.setBoolean(7, participatedInActivities); + preparedStatement.setString(8, mainMotivation); + preparedStatement.setString(9, textareaMotivation); + preparedStatement.setString(10, areaOfExpertise); + preparedStatement.setString(11, elaborated_expertise); + preparedStatement.setString(12, degreeOfParticipation); + preparedStatement.setBoolean(13, true); //data_management + preparedStatement.setBoolean(14, false); //processed_form + preparedStatement.setBoolean(15, false); //user_accepted + // execute insert SQL stetement + preparedStatement .executeUpdate(); + _log.info("Inserting in DB done, sending confirmation to user and notification to managers via email"); + + String copySubmitted = new StringBuffer("\n\n\nCOPY OF INFORMATION SUBMITTED\n\n") + .append("\n").append("Name: ") + .append(name).append(" ").append(surname) + .append("\n").append("Organisation: ") + .append(organisation) + .append("\n").append("Organisation type: ") + .append(organisationType) + .append("\n").append("emailAddress: ") + .append("*** hidden on purpose ***") + .append("\n").append("Country: ") + .append(country) + .append("\n\n").append("Have you participated in the activities of any of our MOVING Regional Multi-Actors Platforms? ") + .append(participatedInActivities) + .append("\n\n").append("What is your main motivation for joining the EU MAP of MOVING? ") + .append(mainMotivation) + .append("\n\n").append("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. ") + .append("\n\n").append(textareaMotivation).append("\n") + .append("\n\n").append("What is your main area of expertise in relation to mountain sustainability and resilience? (Multiple choice): ") + .append(areaOfExpertise) + .append("\n\n").append("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: ") + .append("\n\n").append(elaborated_expertise) + .append("\n\n").append("As a starting point, the degree of participation you commit to is: ") + .append(degreeOfParticipation) + .append("\n").append("\n").append("Data Management: ") + .append("Agreed") + .append("\n\nEND COPY OF INFORMATION SUBMITTED\n\n").toString(); + + + Properties props = System.getProperties(); + Session session = null; + props.put("mail.smtp.host", mailServiceHost); + props.put("mail.smtp.port", mailServicePort); + //use localhost (probaly postfix instance) + session = Session.getDefaultInstance(props); + + sendEmailConfirmationToUser(props, session, emailAddress, copySubmitted); + + String groupIdVREforManagers = GetterUtil.getString(actionRequest.getPreferences().getValue("VREGroupId", StringPool.BLANK)); + if (groupIdVREforManagers != null && groupIdVREforManagers.compareTo("") != 0) { + HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(actionRequest); + sendEmailNotificationToVREManagers(httpRequest, props, session, groupIdVREforManagers, copySubmitted); + } + else { + _log.warn("WARNING, non config found for groupId, no email will be send to VRE Managers"); + } -// String insertTableSQL = "INSERT INTO forms(name, surname, organisation, organisation_type, email, " -// + "country, activities_participation, main_motivation, elaborated_motivation, area_of_expertise, " -// + "elaborated_expertise, degree_of_participation, data_management, datecreated, processed_form, user_accepted) " -// + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,current_timestamp,?,?)"; -// -// PreparedStatement preparedStatement = conn.prepareStatement(insertTableSQL); -// preparedStatement.setString(1, name); -// preparedStatement.setString(2, surname); -// preparedStatement.setString(3, organisation); -// preparedStatement.setString(4, organisationType); -// preparedStatement.setString(5, emailAddress); -// preparedStatement.setString(6, country); -// preparedStatement.setBoolean(7, participatedInActivities); -// preparedStatement.setString(8, mainMotivation); -// preparedStatement.setString(9, textareaMotivation); -// preparedStatement.setString(10, areaOfExpertise); -// preparedStatement.setString(11, elaborated_expertise); -// preparedStatement.setString(12, degree_of_participation); -// preparedStatement.setBoolean(13, true); //data_management -// preparedStatement.setBoolean(14, false); //processed_form -// preparedStatement.setBoolean(15, false); //user_accepted -// // execute insert SQL stetement -// preparedStatement .executeUpdate(); -// _log.info("Inserting in DB done, sending confirmation to user and notification to managers via email"); -// -// String copySubmitted = new StringBuffer("\n\n\nCOPY OF INFORMATION SUBMITTED\n\n") -// .append("\n").append("Name: ") -// .append(name).append(" ").append(surname) -// .append("\n").append("Organisation: ") -// .append(organisation) -// .append("\n").append("Organisation type: ") -// .append(organisationType) -// .append("\n").append("emailAddress: ") -// .append("*** hidden on purpose ***") -// .append("\n").append("Country: ") -// .append(country) -// .append("\n\n").append("Have you participated in the activities of any of our MOVING Regional Multi-Actors Platforms? ") -// .append(participatedInActivities) -// .append("\n\n").append("What is your main motivation for joining the EU MAP of MOVING? ") -// .append(mainMotivation) -// .append("\n\n").append("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. ") -// .append("\n\n").append(textareaMotivation).append("\n") -// .append("\n\n").append("What is your main area of expertise in relation to mountain sustainability and resilience? (Multiple choice): ") -// .append(areaOfExpertise) -// .append("\n\n").append("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: ") -// .append("\n\n").append(elaborated_expertise) -// .append("\n\n").append("As a starting point, the degree of participation you commit to is: ") -// .append(degree_of_participation) -// .append("\n").append("\n").append("Data Management: ") -// .append("Agreed") -// .append("\n\nEND COPY OF INFORMATION SUBMITTED\n\n").toString(); -// -// -// Properties props = System.getProperties(); -// Session session = null; -// props.put("mail.smtp.host", mailServiceHost); -// props.put("mail.smtp.port", mailServicePort); -// //use localhost (probaly postfix instance) -// session = Session.getDefaultInstance(props); -// -// sendEmailConfirmationToUser(props, session, emailAddress, copySubmitted); -// -// String groupIdVREforManagers = GetterUtil.getString(actionRequest.getPreferences().getValue("VREGroupId", StringPool.BLANK)); -// if (groupIdVREforManagers != null && groupIdVREforManagers.compareTo("") != 0) { -// HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(actionRequest); -// sendEmailNotificationToVREManagers(httpRequest, props, session, groupIdVREforManagers, copySubmitted); -// } -// else { -// _log.warn("WARNING, non config found for groupId, no email will be send to VRE Managers"); -// } - } catch (Exception e) { _log.error("Some error while trying to insert form"); e.printStackTrace(); @@ -252,14 +249,14 @@ public class CompileForm extends MVCPortlet { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(MAIL_FROM)); message.setRecipients( - Message.RecipientType.TO, InternetAddress.parse(emailadress)); + Message.RecipientType.TO, InternetAddress.parse(emailadress)); message.setSubject(MAIL_SUBJECT); - message.setText(MAIL_BODY+copySubmitted); - // Send message - Transport.send(message); - _log.info("Sending confirmation email done"); + message.setText(MAIL_BODY+copySubmitted); + // Send message + Transport.send(message); + _log.info("Sending confirmation email done"); } - + /** * * @param props @@ -271,7 +268,7 @@ public class CompileForm extends MVCPortlet { * @throws PortalException */ private void sendEmailNotificationToVREManagers(HttpServletRequest httprequest , Properties props, Session session, String groupIdString, String copySubmitted) throws AddressException, MessagingException, PortalException, SystemException { - _log.info("Sending notification email to VRE-Managers"); + _log.info("Sending notification email to VRE-Managers"); long groupId = Long.parseLong(groupIdString); List vreManagersEmails = getAdministratorsEmails(groupId); for (String emailadress : vreManagersEmails) { @@ -279,7 +276,7 @@ public class CompileForm extends MVCPortlet { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(MAIL_FROM)); message.setRecipients( - Message.RecipientType.TO, InternetAddress.parse(emailadress)); + Message.RecipientType.TO, InternetAddress.parse(emailadress)); message.setSubject(MAIL_SUBJECT_VRE_MANAGER); String vreName = GroupLocalServiceUtil.getGroup(groupId).getName(); String gatewayURL = PortalContext.getConfiguration().getGatewayURL(httprequest); @@ -287,11 +284,11 @@ public class CompileForm extends MVCPortlet { .append(GCubePortalConstants.PREFIX_GROUP_URL) .append("/").append(vreName.toLowerCase()) .append(MANAGE_USERS_REQUESTS_FRIENDLY_URL).toString(); - - message.setText(MAIL_BODY_VRE_MANAGER+manageRequestURL+copySubmitted); - // Send message - Transport.send(message); - _log.info("Sending notification email to VRE-Managers done"); + + message.setText(MAIL_BODY_VRE_MANAGER+manageRequestURL+copySubmitted); + // Send message + Transport.send(message); + _log.info("Sending notification email to VRE-Managers done"); } } /** @@ -323,7 +320,7 @@ public class CompileForm extends MVCPortlet { return adminEmailsList; } - + private static List getOrganisationTypes(Connection conn) throws Exception { _log.debug("getting organisation_types "); List toReturn = new ArrayList<>(); diff --git a/src/main/webapp/css/main.css b/src/main/webapp/css/main.css index 6a44849..b5d722c 100644 --- a/src/main/webapp/css/main.css +++ b/src/main/webapp/css/main.css @@ -16,7 +16,7 @@ } #wrapper label { - display: inline-block; + display: block; max-width: 100%; margin-bottom: 5px; margin-top: 15px; @@ -27,9 +27,10 @@ font-family: "Open Sans", Arial, sans-serif !important; } -#wrapper label.checkbox { +#wrapper label.checkbox, #wrapper label.radio { margin-bottom: 0; margin-top: 5px; + margin-left: 20px; display: block; } .form-display { diff --git a/src/main/webapp/html/form-compile/form-map.jsp b/src/main/webapp/html/form-compile/form-map.jsp index 826d896..6c1fd70 100644 --- a/src/main/webapp/html/form-compile/form-map.jsp +++ b/src/main/webapp/html/form-compile/form-map.jsp @@ -13,7 +13,7 @@ pageContext.setAttribute("main_motivations", main_motivations); pageContext.setAttribute("areas_of_expertise", areas_of_expertise); pageContext.setAttribute("degrees_of_participation", degrees_of_participation); -pageContext.setAttribute("required", "false"); +pageContext.setAttribute("required", "true"); %> @@ -32,11 +32,11 @@ pageContext.setAttribute("required", "false"); + required="false" style="width:300px;" /> - @@ -51,27 +51,32 @@ pageContext.setAttribute("required", "false"); required="${required}" style="width:300px;" /> - + +
+ + +
+
- + + name="mainMotivation" label="${type}" />
- + + name="areaOfExpertiseSelect" cssClass="first-checkbox-hidden" + label="" /> + name="areaOfExpertiseSelect" label="${type}" + showRequiredLabel="false" /> @@ -105,8 +112,8 @@ pageContext.setAttribute("required", "false"); - + @@ -114,7 +121,7 @@ pageContext.setAttribute("required", "false"); - +
 

Data Management

MOVING is responsible for the processing of the personal data @@ -133,9 +140,9 @@ pageContext.setAttribute("required", "false"); Submit Button -->

- - - +
+
@@ -145,6 +152,25 @@ pageContext.setAttribute("required", "false"); + + + + + AUI().use('aui-form-validator', 'aui-overlay-context-panel', function(A) {