Skip to content

Commit

Permalink
Merge pull request #14 from MoodleSync/feature/module-directory
Browse files Browse the repository at this point in the history
Feature/module directory
  • Loading branch information
Daniel-Schroeter authored Feb 16, 2023
2 parents 0841656 + a3203ec commit c90f644
Show file tree
Hide file tree
Showing 35 changed files with 935 additions and 499 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ to publish lecture notes, recordings and other e-learning materials amongst thei
of the fact that the process to upload and manage data via the browser view of Moodle is very time
consuming, the objective of this project was to develop a desktop application used for file
synchronization between a local directory and the learning platform Moodle. Futhermore a Moodle plugin was developed.
For further information about installation and usage please visit the wiki of this repository.

Works with following plugin for Moodle: https://github.com/MoodleSync/sync-plugin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ cli.option.login = Pfad zur Konfigurationsdatei mit Login-Daten
cli.login.properties.missing = Konfigurationsdatei nicht gefunden
cli.login.properties.invalid = Konfigurationsdatei fehlerbehaftet
cli.help.header = Folgende Parameter sind zu \u00FCbergeben
cli.help.footer = \nWenn Sie einen Beitrag leisten oder ein Problem melden m\u00F6chten, besuchen Sie GitHub: https://github.com/lectureStudio/MoodleSync
cli.help.footer = \nWenn Sie einen Beitrag leisten oder ein Problem melden m\u00F6chten, besuchen Sie GitHub: https://github.com/MoodleSync/sync-app
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ cli.option.login = Path to configuration file with login information
cli.login.properties.missing = Configuration file not found
cli.login.properties.invalid = Configuration file is faulty
cli.help.header = The following parameters are required:
cli.help.footer = \nIf you would like to contribute or report an issue, go to GitHub: https://github.com/lectureStudio/MoodleSync
cli.help.footer = \nIf you would like to contribute or report an issue, go to GitHub: https://github.com/MoodleSync/sync-app
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Module {
private Integer instance;
private Integer contextid;
private Integer visible;
private Boolean uservisible;
private String modname;
private String availability;
private List<Content> contents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ public enum MoodleAction {
FTPUpload("Upload file to fileserver"),
FTPSynchronize("Update file on fileserver"),
FTPLink("Link file to moodle"),
FolderUpload("Create new folder and add files"),
FolderSynchronize("Add files to existing folder"),
NotLocalFile("File not locally saved"),
ExistingFile("File is up to date"),
DatatypeNotKnown("Data-Format noch specified"),
DatatypeNotKnown("Data-Format not specified"),
ExistingSection("Exisiting section"),
UploadSection("Create a new section");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface MoodleClient {
* @param moodlewsrestformat Used dataformat.
* @param token The Moodle-token.
* @param function The called Web Service API function.
* @param userid The users id.
* @param userid The user´s id.
* @return a list of moodle-courses.
*/
@POST
Expand All @@ -44,7 +44,7 @@ List<Course> getCourses(@QueryParam("moodlewsrestformat") String moodlewsrestfor
* @param moodlewsrestformat Used dataformat.
* @param token The Moodle-token.
* @param function The called Web Service API function.
* @return a object containing the userid.
* @return an object containing the userid.
*/
@GET
@Path("")
Expand Down Expand Up @@ -122,8 +122,8 @@ void setUrl(@QueryParam("moodlewsrestformat") String moodlewsrestformat, @QueryP
*/
@POST
@Path("")
void setResource(@QueryParam("moodlewsrestformat") String moodlewsrestformat, @QueryParam("wstoken") String token,
@QueryParam("wsfunction") String function, @QueryParam("courseid") int courseid,
void setResource(@QueryParam("moodlewsrestformat") String moodlewsrestformat, @QueryParam("wstoken") String token
, @QueryParam("wsfunction") String function, @QueryParam("courseid") int courseid,
@QueryParam("sectionnum") int sectionnum, @QueryParam("itemid") long itemid, @QueryParam("time") Long time,
@QueryParam("visible") boolean visible, @QueryParam("displayname") String displayname,
@QueryParam("beforemod") Integer beforemod);
Expand All @@ -146,7 +146,25 @@ void setResource(@QueryParam("moodlewsrestformat") String moodlewsrestformat, @Q
void setFolder(@QueryParam("moodlewsrestformat") String moodlewsrestformat, @QueryParam("wstoken") String token,
@QueryParam("wsfunction") String function, @QueryParam("courseid") int courseid,
@QueryParam("sectionnum") int sectionnum, @QueryParam("itemid") long itemid,
@QueryParam("displayname") String displayname, @QueryParam("beforemod") Integer beforemod);
@QueryParam("displayname") String displayname, @QueryParam("time") Long time,
@QueryParam("visible") boolean visible, @QueryParam("beforemod") Integer beforemod);

/**
* Add a file or several files to an existing folder.
*
* @param moodlewsrestformat Used dataformat.
* @param token The Moodle-token.
* @param function The called Web Service API function.
* @param courseid The Moodle-courses id.
* @param itemid The id of the prior uploaded files, which should be presented by the course-module.
* @param contextid The contextid of the folder the files should be added to.
*/
@POST
@Path("")
void addFilesToFolder(@QueryParam("moodlewsrestformat") String moodlewsrestformat,
@QueryParam("wstoken") String token, @QueryParam("wsfunction") String function,
@QueryParam("courseid") int courseid, @QueryParam("itemid") long itemid,
@QueryParam("contextid") int contextid);

/**
* Obtains the course-content of a specific course-section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public void setMoveModule(String token, int cmid, int sectionid, int beforemod)
if (beforemod == -1) {
moodleClient.setMoveModule("json", token, "local_course_move_module_to_specific_position", cmid,
sectionid, null);
}
else {
} else {
moodleClient.setMoveModule("json", token, "local_course_move_module_to_specific_position", cmid,
sectionid, beforemod);
}
Expand All @@ -137,8 +136,7 @@ public void setUrl(String token, int courseid, int section, String urlname, Stri
if (beforemod == -1) {
moodleClient.setUrl("json", token, "local_course_add_new_course_module_url", courseid, section, urlname,
url, time, visible, null);
}
else {
} else {
moodleClient.setUrl("json", token, "local_course_add_new_course_module_url", courseid, section, urlname,
url, time, visible, beforemod);
}
Expand All @@ -161,8 +159,7 @@ public void setResource(String token, int courseid, int section, Long itemid, Lo
if (beforemod == -1) {
moodleClient.setResource("json", token, "local_course_add_new_course_module_resource", courseid, section,
itemid, time, visible, name, null);
}
else {
} else {
moodleClient.setResource("json", token, "local_course_add_new_course_module_resource", courseid, section,
itemid, time, visible, name, beforemod);
}
Expand All @@ -179,19 +176,6 @@ public void removeResource(String token, int cmid) {
moodleClient.removeResource("json", token, "core_course_delete_modules", cmid);
}

/**
* Create a course-module of the type "folder".
*
* @param token The Moodle-token.
* @param courseid A Moodle-courses id.
* @param section The moodle-sections number in the moodle-course.
* @param itemid The id of the prior uploaded files, which should be presented by the course-module.
* @param name The displayname of the course-module.
*/
public void setFolder(String token, int courseid, int section, Long itemid, String name) {
moodleClient.setFolder("json", token, "local_course_add_new_course_module_directory", courseid, section,
itemid, name, null);
}

/**
* Create a course-module of the type "resource" at a specific position inside a course-section.
Expand All @@ -204,18 +188,38 @@ public void setFolder(String token, int courseid, int section, Long itemid, Stri
* @param beforemod The course-module id of the course-module at the supposed position. If beforemod ist null,
* the course-module will be moved to the bottom of the course-section.
*/
public void setFolder(String token, int courseid, int section, Long itemid, String name, int beforemod) {
moodleClient.setFolder("json", token, "local_course_add_new_course_module_directory", courseid, section,
itemid, name, beforemod);
public void setFolder(String token, int courseid, int section, Long itemid, String name, Long time, boolean visible,
int beforemod) {
if (beforemod == -1) {
moodleClient.setFolder("json", token, "local_course_add_new_course_module_directory", courseid, section,
itemid, name, time, visible, null);
} else {
moodleClient.setFolder("json", token, "local_course_add_new_course_module_directory", courseid, section,
itemid, name, time, visible, beforemod);
}
}

/**
* Add a file or several files to an existing folder. Note: to upload several files, it is necessary that all
* files are uploaded one after another with the same itemid.
*
* @param token The Moodle-token.
* @param courseid A Moodle-courses id.
* @param itemid The id of the prior uploaded file(s), which should be presented by the course-module.
* @param contextid The contextid of the folder the files should be added to.
*/
public void addFilesToFolder(String token, int courseid, Long itemid, int contextid) {
moodleClient.addFilesToFolder("json", token, "local_course_add_files_to_directory", courseid, itemid,
contextid);
}

/**
* Method used to create a new course section.
*
* @param token The Moodle-token.
* @param courseid A Moodle-courses id.
* @param token The Moodle-token.
* @param courseid A Moodle-courses id.
* @param sectionname The name of the new section.
* @param sectionnum The moodle-sections number in the moodle-course.
* @param sectionnum The moodle-sections number in the moodle-course.
*/
public void setSection(String token, int courseid, String sectionname, int sectionnum) {
moodleClient.setSection("json", token, "local_course_add_new_section", courseid, sectionname, sectionnum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,52 @@ public MoodleUpload upload(String name, String pathname, String moodleUrl, Strin
}
}

public MoodleUpload upload(String name, String pathname, String moodleUrl, String token, Long itemid) {
try {
OkHttpClient.Builder builder = new OkHttpClient.Builder();

//Usage of https
if (moodleUrl.startsWith("https")) {
X509TrustManager trustManager;
SSLSocketFactory sslSocketFactory;
try {
trustManager = createTrustManager();
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new TrustManager[]{trustManager}, new java.security.SecureRandom());
sslSocketFactory = sslContext.getSocketFactory();
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
builder.sslSocketFactory(sslSocketFactory, trustManager);
builder.hostnameVerifier((hostname, sslSession) -> hostname
.equalsIgnoreCase(sslSession.getPeerHost()));

}
//Execution of the http-request
OkHttpClient client = builder.build();
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart(name, pathname,
RequestBody.create(MediaType.parse("application/octet-stream"),
new File(pathname)))
.build();
Request request = new Request.Builder()
.url(moodleUrl + "/webservice/upload.php?token=" + token + "&itemid=" + itemid)
.method("POST", body)
.build();
ResponseBody response = client.newCall(request).execute().body();
String bodystring = response.string();
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("--------------------------------------" + bodystring);
List<MoodleUpload> entity = objectMapper.readValue(bodystring, new TypeReference<List<MoodleUpload>>() {
});
System.out.println(entity);
return entity.get(0);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}


/**
* Method user for generating a needed X509TrustManager for https-communication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import moodle.sync.javafx.model.syncTableElement;
import moodle.sync.javafx.model.SyncTableElement;

/**
* Class implementing a Checkbox as the content of a TableCell.
*
* @author Daniel Schröter
*/
public class AvailabilityCellFactory implements Callback<TableColumn<syncTableElement, Boolean>, TableCell<syncTableElement, Boolean>> {
public class AvailabilityCellFactory implements Callback<TableColumn<SyncTableElement, Boolean>, TableCell<SyncTableElement, Boolean>> {
@Override
public TableCell<syncTableElement, Boolean> call(TableColumn<syncTableElement, Boolean> p) {
AvailabilityCheckBoxCell <syncTableElement, Boolean> cell = new AvailabilityCheckBoxCell<syncTableElement, Boolean>();
public TableCell<SyncTableElement, Boolean> call(TableColumn<SyncTableElement, Boolean> p) {
AvailabilityCheckBoxCell <SyncTableElement, Boolean> cell = new AvailabilityCheckBoxCell<SyncTableElement, Boolean>();
cell.setAlignment(Pos.CENTER);
cell.setStyle("-fx-alignment: CENTER;");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import moodle.sync.javafx.model.syncTableElement;
import moodle.sync.javafx.model.SyncTableElement;

/**
* Class used for determining the state of a CheckBox inside the "sync-page"-table.
*
* @author Daniel Schröter
*/
public class AvailabilityCellValueFactory implements Callback<TableColumn.CellDataFeatures<syncTableElement,Boolean>, ObservableValue<Boolean>> {
public class AvailabilityCellValueFactory implements Callback<TableColumn.CellDataFeatures<SyncTableElement,Boolean>, ObservableValue<Boolean>> {
@Override
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<syncTableElement, Boolean> param)
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<SyncTableElement, Boolean> param)
{
syncTableElement elem = param.getValue();
SyncTableElement elem = param.getValue();
//selectedProperty should be used to determine the state.
param.getValue().visibleProperty();
SimpleBooleanProperty booleanProp= (SimpleBooleanProperty) elem.visibleProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.util.StringConverter;
import moodle.sync.core.util.MoodleAction;
import moodle.sync.javafx.model.syncTableElement;
import moodle.sync.javafx.model.SyncTableElement;

/**
* Class used to display the selctedProperty-value inside a CheckBoxTreeTableCell.
*
* @author Daniel Schröter
*/
public class AvailabilityCheckBoxCell<U, B> extends CheckBoxTableCell<syncTableElement, Boolean> {
public class AvailabilityCheckBoxCell<U, B> extends CheckBoxTableCell<SyncTableElement, Boolean> {

private CheckBox checkBox;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import moodle.sync.javafx.model.TimeDateElement;
import moodle.sync.javafx.model.syncTableElement;
import moodle.sync.javafx.model.SyncTableElement;

/**
* Class used for determining the date and time of a upload inside the "sync-page"-table.
*
* @author Daniel Schröter
*/
public class AvailableDateTimeTableCellFactory implements Callback<TableColumn<syncTableElement, TimeDateElement>, TableCell<syncTableElement, TimeDateElement>> {
public class AvailableDateTimeTableCellFactory implements Callback<TableColumn<SyncTableElement, TimeDateElement>, TableCell<SyncTableElement, TimeDateElement>> {
@Override
public TableCell<syncTableElement, TimeDateElement> call(TableColumn<syncTableElement, TimeDateElement> p) {
LocalDateTimeCell<syncTableElement, TimeDateElement> cell = new LocalDateTimeCell<syncTableElement, TimeDateElement>();
public TableCell<SyncTableElement, TimeDateElement> call(TableColumn<SyncTableElement, TimeDateElement> p) {
LocalDateTimeCell<SyncTableElement, TimeDateElement> cell = new LocalDateTimeCell<SyncTableElement, TimeDateElement>();
cell.setAlignment(Pos.CENTER);
cell.setStyle("-fx-alignment: CENTER;");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import moodle.sync.javafx.model.syncTableElement;
import moodle.sync.javafx.model.SyncTableElement;

/**
* Class implementing a Checkbox as the content of a TableCell.
*
* @author Daniel Schröter
*/
public class CheckBoxTableCellFactory implements Callback<TableColumn<syncTableElement, Boolean>, TableCell<syncTableElement, Boolean>> {
public class CheckBoxTableCellFactory implements Callback<TableColumn<SyncTableElement, Boolean>, TableCell<SyncTableElement, Boolean>> {
@Override
public TableCell<syncTableElement, Boolean> call(TableColumn<syncTableElement, Boolean> p) {
UploadCheckBoxCell<syncTableElement, Boolean> cell = new UploadCheckBoxCell<syncTableElement, Boolean>();
public TableCell<SyncTableElement, Boolean> call(TableColumn<SyncTableElement, Boolean> p) {
UploadCheckBoxCell<SyncTableElement, Boolean> cell = new UploadCheckBoxCell<SyncTableElement, Boolean>();
cell.setAlignment(Pos.CENTER);
cell.setStyle("-fx-alignment: CENTER;");

Expand Down
Loading

0 comments on commit c90f644

Please sign in to comment.