forked from MoodleSync/sync-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into main
- Loading branch information
Showing
47 changed files
with
1,915 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
*/ | ||
public class Content { | ||
private String filename; | ||
private String fileurl; | ||
private Long timemodified; | ||
} |
18 changes: 18 additions & 0 deletions
18
moodle-sync-core/src/main/java/moodle/sync/core/model/json/CoursePermissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package moodle.sync.core.model.json; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CoursePermissions { | ||
|
||
private List<OptionPermissions> options; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
moodle-sync-core/src/main/java/moodle/sync/core/model/json/OptionPermissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package moodle.sync.core.model.json; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class OptionPermissions { | ||
|
||
private String name; | ||
|
||
private Boolean available; | ||
} |
19 changes: 19 additions & 0 deletions
19
moodle-sync-core/src/main/java/moodle/sync/core/model/json/Permissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package moodle.sync.core.model.json; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Permissions { | ||
|
||
private List<CoursePermissions> courses; | ||
|
||
} | ||
|
34 changes: 34 additions & 0 deletions
34
moodle-sync-core/src/main/java/moodle/sync/core/util/FileDownloadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package moodle.sync.core.util; | ||
|
||
import moodle.sync.core.web.service.MoodleDownloadService; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
public final class FileDownloadService { | ||
|
||
public static void getFile(String url, String token, String path, String name, String lastModified) throws Exception { | ||
MoodleDownloadService moodleDownloadService = new MoodleDownloadService(url); | ||
try (InputStream download = moodleDownloadService.getDownload(token)) { | ||
if (download.available() != 0) { | ||
File targetFile = new File(path + "/" + name); | ||
java.nio.file.Files.copy(download, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
targetFile.setLastModified(((Long.parseLong(lastModified)*1000)-1)); | ||
} | ||
} | ||
} | ||
|
||
/** Usage: | ||
* try{ | ||
* FileDownloadService.getFile("https://localhost/webservice/pluginfile" + | ||
* ".php/21/mod_resource/content/0/TheModel.pdf?forcedownload=1", token, | ||
* "C:/Users" + | ||
* "/danie/OneDrive/Desktop", "Testdatei.pdf", lastmodifiedtime); | ||
* } catch (Exception e){ | ||
* logException(e, "Sync failed"); | ||
* } | ||
* } | ||
*/ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
moodle-sync-core/src/main/java/moodle/sync/core/web/client/MoodleDownloadClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package moodle.sync.core.web.client; | ||
|
||
import moodle.sync.core.model.json.JsonConfigProvider; | ||
import moodle.sync.core.web.filter.LoggingFilter; | ||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.annotation.RegisterProviders; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import java.io.InputStream; | ||
|
||
|
||
@Path("") | ||
@RegisterProviders({@RegisterProvider(LoggingFilter.class), @RegisterProvider(JsonConfigProvider.class),}) | ||
public interface MoodleDownloadClient { | ||
|
||
@GET | ||
@Path("") | ||
@Produces(MediaType.MEDIA_TYPE_WILDCARD) | ||
InputStream getDownload(@QueryParam("token") String token); | ||
} |
76 changes: 76 additions & 0 deletions
76
moodle-sync-core/src/main/java/moodle/sync/core/web/service/MoodleDownloadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package moodle.sync.core.web.service; | ||
|
||
import moodle.sync.core.web.client.MoodleDownloadClient; | ||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
public class MoodleDownloadService { | ||
|
||
private MoodleDownloadClient moodleClient; | ||
|
||
/** | ||
* Creates a new MoodleService. | ||
* | ||
* @param apiUrl The url of the Moodle-platform. | ||
*/ | ||
public MoodleDownloadService(String apiUrl) { | ||
setApiUrl(apiUrl); | ||
} | ||
|
||
/** | ||
* Method which instantiates a MoodleClient. | ||
* | ||
* @param apiUrl The url of the Moodle-platform. | ||
*/ | ||
public void setApiUrl(String apiUrl) { | ||
//Parameter checks. | ||
if (apiUrl == null || apiUrl.isEmpty() || apiUrl.isBlank()) { | ||
return; | ||
} | ||
RestClientBuilder builder = RestClientBuilder.newBuilder(); | ||
builder.baseUri(URI.create(apiUrl)); | ||
//Usage of https. | ||
if (apiUrl.startsWith("https")) { | ||
builder.sslContext(createSSLContext()); | ||
builder.hostnameVerifier((hostname, sslSession) -> hostname.equalsIgnoreCase(sslSession.getPeerHost())); | ||
} | ||
//MoodleClient is instantiated by classes of the MicroProfile Rest Client. | ||
moodleClient = builder.build(MoodleDownloadClient.class); | ||
} | ||
|
||
public InputStream getDownload(String token) { | ||
return moodleClient.getDownload(token); | ||
} | ||
|
||
private static SSLContext createSSLContext() { | ||
SSLContext sslContext; | ||
|
||
try { | ||
TrustManager tm = new X509TrustManager() { | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
} | ||
|
||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
} | ||
|
||
public X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
}; | ||
|
||
sslContext = SSLContext.getInstance("TLSv1.2"); | ||
sslContext.init(null, new TrustManager[]{tm}, null); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return sslContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
moodle-sync-fx/src/main/java/moodle/sync/event/DownloadItemEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package moodle.sync.event; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import moodle.sync.javafx.model.SyncTableElement; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class DownloadItemEvent { | ||
|
||
private SyncTableElement element; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.