Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[revert] removed moodle import feature, lives on in a separate branch…

… (see uni_leipzig).

This feature is specific for our setup, won't work anywhere else unless getting adjusted alot.
  • Loading branch information...
commit 2026040e484db8c164c9c00d5e1790d2fd747b6c 1 parent e807a7c
@smee authored
View
5 examServer/pom.xml
@@ -271,11 +271,6 @@
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>de.elatexam</groupId>
- <artifactId>httprobot</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
<groupId>servletapi</groupId>
<artifactId>servletapi</artifactId>
<version>2.4</version>
View
145 .../src/main/java/de/thorstenberger/examServer/webapp/action/userimport/ImportMoodleGroupMembersAction.java
@@ -1,145 +0,0 @@
-/*
-
-Copyright (C) 2010 Steffen Dienst
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program 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 General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package de.thorstenberger.examServer.webapp.action.userimport;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.struts.action.ActionForm;
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.action.ActionMapping;
-
-import de.elatexam.httprobot.Robot;
-import de.thorstenberger.examServer.webapp.form.ImportMoodleGroupMembersForm;
-import de.thorstenberger.examServer.ws.opal.Member;
-
-/**
- * Import user details from a moodle course via webscraping.
- *
- * @author Steffen Dienst
- *
- */
-public class ImportMoodleGroupMembersAction extends AbstractImportMembersAction {
- @Override
- public ActionForward execute(
- final ActionMapping mapping,
- final ActionForm form_,
- final HttpServletRequest request,
- final HttpServletResponse response)
- throws Exception {
-
- final ImportMoodleGroupMembersForm form = (ImportMoodleGroupMembersForm) form_;
-
- if (!StringUtils.isEmpty(form.getUserId()) && !StringUtils.isEmpty(form.getPassword())) {
- if ("searchCourses".equals(request.getParameter("action")) || StringUtils.isEmpty(form.getCourseName())) {
-
- // fetch all courses of this user
- final List<String> courses = fetchCoursesOf(form.getUserId(), form.getPassword());
- courses.remove("Help");// remove invalid course
- courses.remove("Hilfe");// remove invalid course
- request.setAttribute("knownCourses", courses);
- } else {
- // fetch all group participants
- final List<Member> members = fetchGroupMembers(form.getUserId(), form.getPassword(), form.getCourseName());
- final List<Member> importedMembers = storeImportedUsers(members);
-
- request.setAttribute("importedMembers", importedMembers);
- }
- }
-
- return mapping.findForward("success");
- }
-
- /**
- * Find this user's courses from moodle.
- *
- * @param userId
- * @param password
- * @return
- */
- private List<String> fetchCoursesOf(final String userId, final String password) {
- final Robot robot = new Robot(new String[]{"un:"+userId,"pw:"+password});
- robot.run(this.getClass().getResourceAsStream("moodleMyCourses.xml"));
- final String[] textResult = robot.getLastTextResult().split("\n");
- // return mutable list
- return new ArrayList<String>(Arrays.asList(textResult));
- }
-
-
- /**
- * Fetch all members of the given course.
- *
- * @param form
- * input data as entered by user
- * @return
- */
- private List<Member> fetchGroupMembers(final String userId, final String password, final String courseName) {
- final Robot robot = new Robot(new String[] { "un:" + userId, "pw:" + password, "coursename:" + courseName });
- robot.run(this.getClass().getResourceAsStream("moodleParticipants.xml"));
- final String participantsCsv = new String(robot.getLastByteResult(), Charset.forName("UTF8"));
-
- return loadParticipantsFromCsv(participantsCsv);
- }
-
- /**
- * @param participantsCsv
- * @return
- */
- private List<Member> loadParticipantsFromCsv(final String participantsCsv) {
- final List<Member> result = new LinkedList<Member>();
- final BufferedReader br = new BufferedReader(new StringReader(participantsCsv));
- try {
- final String header = br.readLine();
- log.debug("Importing moodle users, csv header line: " + header);
-
- String line = null;
- while ((line = br.readLine()) != null) {
- final String[] lineParts = line.split(";");
- if (lineParts.length == 4) {
- final Member member = new Member();
- // username;email;firstname;lastname
- log.trace("importing line: " + line);
- member.setMemberId(lineParts[0]);
- member.setEmail(lineParts[1]);
- member.setFirstname(lineParts[2]);
- member.setLastname(lineParts[3]);
-
- result.add(member);
- } else {
- log.warn(String.format("Could not import line '%s' from csv, does not have 4 components seperated by ;", line));
- }
- }
-
- } catch (final IOException e) {
- log.error("Could not import moodle csv", e);
- }
- return result;
- }
-
-}
View
2  examServer/src/main/resources/ApplicationResources_de.properties
@@ -232,7 +232,5 @@ taskConfig.title = Aufgaben-Konfiguration
taskConfig.heading = Aufgaben-Konfiguration
taskConfig.saved = Ihre Einstellungen wurden gespeichert.
# -- import users
-import.moodle.heading = Benutzerimport aus moodle
-import.moodle.title = Benutzerimport
import.opal.heading = Benutzerimport aus moodle
import.opal.title = Benutzerimport
View
57 examServer/src/main/resources/de/thorstenberger/examServer/webapp/action/userimport/moodleMyCourses.xml
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<robotPlan>
- <step>
- <mode>GET</mode>
- <url>https://moodle.uni-leipzig.de</url>
- <element />
- <param />
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>Login</name>
- <element />
- <param />
- </step>
- <step>
- <mode>POST</mode>
- <name>formular</name>
- <element />
- <param>
- <type>select</type>
- <name>gruppe</name>
- <value>inf</value>
- <state />
- </param>
- <param>
- <type>input</type>
- <name>username</name>
- <value>param:un</value>
- <state />
- </param>
- <param>
- <type>input</type>
- <name>password</name>
- <value>param:pw</value>
- <state />
- </param>
- <param>
- <type>hidden</type>
- <name>testcookies</name>
- <value>1</value>
- <state />
- </param>
- <button>submitOk</button>
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>Mein Moodle</name>
- <element />
- <param />
- </step>
- <step>
- <mode>EXTRACT_Links</mode>
- <name>course/view.php</name>
- <element />
- <param />
- </step>
-</robotPlan>
View
123 examServer/src/main/resources/de/thorstenberger/examServer/webapp/action/userimport/moodleParticipants.xml
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<robotPlan>
- <step>
- <mode>GET</mode>
- <url>https://moodle.uni-leipzig.de</url>
- <element />
- <param />
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>Login</name>
- <element />
- <param />
- </step>
- <step>
- <mode>POST</mode>
- <name>formular</name>
- <element />
- <param>
- <type>select</type>
- <name>gruppe</name>
- <value>inf</value>
- <state />
- </param>
- <param>
- <type>input</type>
- <name>username</name>
- <value>param:un</value>
- <state />
- </param>
- <param>
- <type>input</type>
- <name>password</name>
- <value>param:pw</value>
- <state />
- </param>
- <param>
- <type>hidden</type>
- <name>testcookies</name>
- <value>1</value>
- <state />
- </param>
- <button>submitOk</button>
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>Mein Moodle</name>
- <element />
- <param />
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>param:coursename</name>
- <element />
- <param />
- </step>
- <step>
- <mode>GET_Link</mode>
- <name>Teilnehmer exportieren</name>
- <element />
- <param />
- </step>
- <step>
- <mode>POST</mode>
- <name>roleform</name>
- <element />
- <param>
- <type>select</type>
- <name>role</name>
- <value>5</value>
- <state />
- </param>
- <param>
- <type>checkbox</type>
- <name>username</name>
- <state>true</state>
- <value/>
- </param>
- <param>
- <type>checkbox</type>
- <name>email</name>
- <state>true</state>
- <value/>
- </param>
- <param>
- <type>checkbox</type>
- <name>firstname</name>
- <state>true</state>
- <value/>
- </param>
- <param>
- <type>checkbox</type>
- <name>lastname</name>
- <state>true</state>
- <value/>
- </param>
- <param>
- <type>select</type>
- <name>username_column</name>
- <value>1</value>
- <state />
- </param>
- <param>
- <type>select</type>
- <name>email_column</name>
- <value>2</value>
- <state />
- </param>
- <param>
- <type>select</type>
- <name>firstname_column</name>
- <value>3</value>
- <state />
- </param>
- <param>
- <type>select</type>
- <name>lastname_column</name>
- <value>4</value>
- <state />
- </param>
- <button>als Textdatei downloaden</button>
- </step>
-</robotPlan>
View
66 examServer/src/main/webapp/WEB-INF/pages/importMoodle.jsp
@@ -1,66 +0,0 @@
-<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
-<%@ include file="/common/taglibs.jsp"%>
-
-
-<head>
- <title><fmt:message key="import.moodle.title"/></title>
- <content tag="heading"><fmt:message key="import.moodle.heading"/></content>
- <meta name="menu" content="MainMenu"/>
-</head>
-
-<div class="separator">
-Hier k&ouml;nnen Sie Mitglieder einer moodle-Gruppe ins Pr&uuml;fungssystem importieren.
-</div>
-
-<br/><br/>
-
-<html:form action="/importMoodleUsers.do">
-<table border="0">
-
-<c:choose>
- <c:when test="${empty knownCourses}">
- <tr>
- <td>Moodle-Benutzername (Email): </td><td><html-el:text property="userId" size="60"/></td>
- </tr>
- <tr>
- <td>Passwort: </td><td><html-el:password property="password" size="60"/></td>
- </tr>
- <tr>
- <td></td>
- <td><html:submit property="searchCourses">Meine Kurse suchen</html:submit></td>
- </tr>
- </c:when>
- <c:otherwise>
- <html-el:hidden property="userId"/>
- <html-el:hidden property="password"/>
- <tr>
- <td>Bitte wählen Sie:</td>
- <td>
- <c:forEach var="course" items="${knownCourses}">
- <html-el:radio property="courseName" value="${course}"/><c:out value="${course}"/><br/>
- </c:forEach>
- </td>
- </tr>
- <tr>
- <td></td>
- <td><html:submit>Importieren</html:submit></td>
- </tr>
- </c:otherwise>
-</c:choose>
-</table>
-</html:form>
-<br/>
-<br/>
-
-<c:if test="${not empty importedMembers}">
- <h2>
- Importierte Benutzer:
- </h2>
- <display:table name="importedMembers" cellspacing="0" cellpadding="0" requestURI=""
- defaultsort="1" id="users" pagesize="25" class="table" export="false">
- <display:column property="memberId" escapeXml="true" sortable="true" titleKey="userForm.username" style="width: 25%"/>
- <display:column property="firstname" escapeXml="true" sortable="true" titleKey="userForm.firstName" style="width: 25%"/>
- <display:column property="lastname" escapeXml="true" sortable="true" titleKey="userForm.lastName" style="width: 34%"/>
- <display:column property="email" sortable="true" titleKey="userForm.email" style="width: 25%" autolink="true" media="html"/>
- </display:table>
-</c:if>
View
1  examServer/src/main/webapp/WEB-INF/pages/userList.jsp
@@ -54,5 +54,4 @@
<br/>
<br/>
<h2>Benutzer importieren</h2>
-<html:link action="/moodleUsers">... aus moodle</html:link><br/>
<html:link action="/opalUsers">... aus OPAL</html:link>
View
7 examServer/src/main/webapp/WEB-INF/struts-config.xml
@@ -18,7 +18,6 @@
<form-bean name="taskForm" type="de.thorstenberger.examServer.webapp.form.TaskForm"/>
<form-bean name="taskUploadForm" type="de.thorstenberger.examServer.webapp.form.TaskDefUploadForm"/>
<form-bean name="opalGroupMembersImportForm" type="de.thorstenberger.examServer.webapp.form.ImportOpalGroupMembersForm"/>
- <form-bean name="moodleGroupMembersImportForm" type="de.thorstenberger.examServer.webapp.form.ImportMoodleGroupMembersForm"/>
<form-bean name="loginConfigForm" type="de.thorstenberger.examServer.webapp.form.LoginConfigForm"/>
<form-bean name="systemConfigForm" type="de.thorstenberger.examServer.webapp.form.SystemConfigForm"/>
</form-beans>
@@ -155,12 +154,6 @@
</action>
<action path="/opalUsers" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/importOpal.jsp" roles="admin">
</action>
- <!-- actions for importing users from a moodle course -->
- <action path="/importMoodleUsers" name="moodleGroupMembersImportForm" type="de.thorstenberger.examServer.webapp.action.userimport.ImportMoodleGroupMembersAction" scope="request" validate="false" input="/WEB-INF/pages/importMoodle.jsp" roles="admin">
- <forward name="success" redirect="false" path="/WEB-INF/pages/importMoodle.jsp"/>
- </action>
- <action path="/moodleUsers" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/importMoodle.jsp" roles="admin">
- </action>
</action-mappings>
<controller inputForward="true" maxFileSize="2M" nocache="true"/>
<message-resources parameter="ApplicationResources"/>
Please sign in to comment.
Something went wrong with that request. Please try again.