From 298758030f1fe534247fe5989f32f505675e2aaa Mon Sep 17 00:00:00 2001 From: MarcTheDev Date: Sun, 10 Dec 2023 21:46:07 +0100 Subject: [PATCH] Initial commit --- .gitignore | 38 +++ .idea/.gitignore | 8 + .idea/discord.xml | 7 + .idea/encodings.xml | 7 + .idea/inspectionProfiles/Project_Default.xml | 8 + .idea/misc.xml | 20 ++ .idea/vcs.xml | 6 + pom.xml | 118 +++++++ src/main/java/MarcSync/Client.java | 74 +++++ src/main/java/MarcSync/Collection.java | 314 ++++++++++++++++++ src/main/java/MarcSync/Entry.java | 169 ++++++++++ .../classes/CollectionUpdatePayload.java | 9 + src/main/java/MarcSync/classes/EntryData.java | 11 + .../MarcSync/classes/EntryDataPayload.java | 9 + .../MarcSync/classes/EntryFilterPayload.java | 9 + .../java/MarcSync/classes/EntryResponse.java | 5 + .../MarcSync/classes/EntryUpdatePayload.java | 11 + 17 files changed, 823 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/discord.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/MarcSync/Client.java create mode 100644 src/main/java/MarcSync/Collection.java create mode 100644 src/main/java/MarcSync/Entry.java create mode 100644 src/main/java/MarcSync/classes/CollectionUpdatePayload.java create mode 100644 src/main/java/MarcSync/classes/EntryData.java create mode 100644 src/main/java/MarcSync/classes/EntryDataPayload.java create mode 100644 src/main/java/MarcSync/classes/EntryFilterPayload.java create mode 100644 src/main/java/MarcSync/classes/EntryResponse.java create mode 100644 src/main/java/MarcSync/classes/EntryUpdatePayload.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..869c305 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..04e2e4d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aa92a88 --- /dev/null +++ b/pom.xml @@ -0,0 +1,118 @@ + + + 4.0.0 + + dev.marcsync + marcsync-java-client + 0.1.0 + + marcsync-java-client + Java client for the MarcSync API + https://github.com/marcsync/marcsync-java-client + + + Marcel Lorbeer + marcthedev@marcsync.dev + MarcSync + https://marcsync.dev + + + + + MIT License + + + + scm:git:git://github.com/marcsync/marcsync-java-client + + + + true + 21 + 21 + UTF-8 + + + + + com.google.code.gson + gson + 2.10.1 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.16.0 + + + + + + + org.sonatype.central + central-publishing-maven-plugin + 0.1.2 + true + + central + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + ${java.home}/bin/javadoc + + + + attach-javadocs + + jar + + + + + + + + + + release + + false + + + + + \ No newline at end of file diff --git a/src/main/java/MarcSync/Client.java b/src/main/java/MarcSync/Client.java new file mode 100644 index 0000000..30a747d --- /dev/null +++ b/src/main/java/MarcSync/Client.java @@ -0,0 +1,74 @@ +package MarcSync; + +import java.io.IOException; +import java.net.*; + +public class Client { + + private final String _accessToken; + + /** + * Creates a new MarcSync client. + * @param accessToken The access token to use for communication with MarcSync + */ + public Client(String accessToken) { + _accessToken = accessToken; + } + + /** + * @param collectionName The name of the collection to use + * @return A new instance of the MarcSync collection + * + * @see Collection + */ + public Collection getCollection(String collectionName) { + return new Collection(_accessToken, collectionName); + } + + /** + * @param collectionName The name of the collection to use + * @return A new instance of the MarcSync collection + * + * @throws IOException + * @throws URISyntaxException + * @see Collection + * + *

+ * Note: This method is useful if you want to fetch the collection from the server to check if it exists before using it. + *

+ */ + public Collection fetchCollection(String collectionName) throws IOException, URISyntaxException { + URL url = new URI("https://api.marcsync.dev/v0/collection/" + collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to fetch collection: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return new Collection(_accessToken, collectionName); + } + + /** + * + * @param collectionName The name of the collection to create + * @return A new instance of the MarcSync collection + * + * @throws IOException + * @throws URISyntaxException + */ + public Collection createCollection(String collectionName) throws IOException, URISyntaxException { + URL url = new URI("https://api.marcsync.dev/v0/collection/" + collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to create collection: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return new Collection(_accessToken, collectionName); + } +} diff --git a/src/main/java/MarcSync/Collection.java b/src/main/java/MarcSync/Collection.java new file mode 100644 index 0000000..c77f104 --- /dev/null +++ b/src/main/java/MarcSync/Collection.java @@ -0,0 +1,314 @@ +package MarcSync; + +import MarcSync.classes.*; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.google.gson.*; + +import java.io.*; +import java.net.*; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +public class Collection { + + private final String _accessToken; + private final String _collectionName; + private final ObjectMapper _mapper; + + /** + * Creates a new instance of the MarcSync collection + * @param accessToken The access token to use for communication with MarcSync + * @param collectionName The name of the collection to use + * + * @see Client + **/ + public Collection(String accessToken, String collectionName) { + _accessToken = accessToken; + _collectionName = collectionName; + + _mapper = new ObjectMapper(); + _mapper.enable(SerializationFeature.INDENT_OUTPUT); + _mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + } + + /** + * + * Warning: + * @throws URISyntaxException + * @throws IOException + *

+ * Note: This method will delete the collection and all of its entries. This action cannot be undone. + *

+ * + */ + public void drop() throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v0/collection/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("DELETE"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to drop collection: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } + + /** + * @return The name of the collection + */ + public String setName(String name) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v0/collection/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(new Gson().toJson(new CollectionUpdatePayload(name)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to rename collection: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return name; + } + + /** + * @return The name of the collection + */ + public String getName() { + return _collectionName; + } + + /** + * + * @return Whether or not the collection exists + * + *

+ * Note: This method is useful if you want to fetch the collection from the server to check if it exists before using it. + *

+ * + */ + public boolean exists() { + try { + URL url = new URI("https://api.marcsync.dev/v0/collection/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + + return connection.getResponseCode() == 200; + } catch (Exception e) { + return false; + } + } + + /** + * Creates an entry in the collection + * + * @return A new instance of the MarcSync entry + * + */ + public Entry createEntry(EntryData entryData) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v0/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryDataPayload(entryData)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to create entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return new Entry(_accessToken, _collectionName, entryData); + } + + + /** + * + * @return The entry with the specified ID + * + */ + public Entry getEntryById(String id) throws URISyntaxException, IOException, InterruptedException { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .method("GET", HttpRequest.BodyPublishers.ofString(_mapper.writeValueAsString(new EntryFilterPayload(new EntryData() {{ + put("_id", id); + }})))) + .uri(new URI("https://api.marcsync.dev/v1/entries/" + _collectionName)) + .header("accept", "application/json") + .header("authorization", _accessToken) + .header("content-type", "application/json") + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + if (response.statusCode() != 200) { + throw new IOException("Failed to get entry: " + response.statusCode() + " " + response.body()); + } + + return new Entry(_accessToken, _collectionName, new Gson().fromJson(response.body(), EntryResponse.class).entries[0]); + } + + /** + * + * @return The entries with the specified filter + * + *

+ * Note: This method is useful if you want to fetch multiple entries from the server at once. + *

+ * + * @see Entry + * @see EntryData + * + */ + public Entry[] getEntries(EntryData filters) throws IOException, InterruptedException, URISyntaxException { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .method("GET", HttpRequest.BodyPublishers.ofString(_mapper.writeValueAsString(new EntryFilterPayload(filters)))) + .uri(new URI("https://api.marcsync.dev/v1/entries/" + _collectionName)) + .header("accept", "application/json") + .header("authorization", _accessToken) + .header("content-type", "application/json") + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + if (response.statusCode() != 200) { + throw new IOException("Failed to get entries: " + response.statusCode() + " " + response.body()); + } + + return Arrays.stream(new Gson().fromJson(response.body(), EntryResponse.class).entries).map(entryData -> new Entry(_accessToken, _collectionName, entryData)).toArray(Entry[]::new); + } + + /** + * + * Deletes the entry with the specified ID + *

+ * Note: Will delete the entry from the collection. This action cannot be undone. + *

+ * + */ + public void deleteEntryById(String id) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("DELETE"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(new Gson().toJson(new EntryFilterPayload(new EntryData() {{ + put("_id", id); + }})).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to delete entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } + + /** + * + * Deletes the entries matching with the specified filter + *

+ * Note: Will delete the matching entries from the collection. This action cannot be undone. + *

+ * + * @see EntryData + */ + public void deleteEntries(EntryData filters) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("DELETE"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryFilterPayload(filters)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to delete entries: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } + + /** + * + * Updates the entry with the specified ID + * + * @see Entry + * @see EntryData + */ + public void updateEntryById(String id, EntryData entryData) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryUpdatePayload(new EntryData() {{ + put("_id", id); + }}, entryData)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to update entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } + + /** + * + * Updates the entries matching with the specified filter + * + * @see Entry + * @see EntryData + */ + public void updateEntries(EntryData filters, EntryData entryData) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryUpdatePayload(filters, entryData)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to update entries: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } + + private static String readResponse(InputStream inputStream) throws IOException { + StringBuilder response = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + } + return response.toString(); + } +} diff --git a/src/main/java/MarcSync/Entry.java b/src/main/java/MarcSync/Entry.java new file mode 100644 index 0000000..3a4a8f1 --- /dev/null +++ b/src/main/java/MarcSync/Entry.java @@ -0,0 +1,169 @@ +package MarcSync; + +import MarcSync.classes.EntryData; +import MarcSync.classes.EntryFilterPayload; +import MarcSync.classes.EntryUpdatePayload; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.*; +import java.nio.charset.StandardCharsets; + +public class Entry { + + private final String _accessToken; + private final String _collectionName; + private final EntryData _entryData; + private final ObjectMapper _mapper; + + public Entry(String accessToken, String collectionName, EntryData entryData) { + _accessToken = accessToken; + _collectionName = collectionName; + _entryData = entryData; + + _mapper = new ObjectMapper(); + _mapper.enable(SerializationFeature.INDENT_OUTPUT); + _mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + } + + /** + * + * @return The EntryData object of the entry + * + *

+ * Note: This method is useful if you want to get the values of the entry. + *

+ * + * @see EntryData + * + */ + public EntryData getValues() { + return _entryData; + } + + /** + * + * @param key The key of the value to get + * @return The value of the specified key + * + *

+ * Note: This method is useful if you want to get the value of a specific key without specifying the type. + *

+ * + * @see EntryData + * + */ + public Object getValue(String key) { + return _entryData.get(key); + } + + /** + * + * @return The name of the collection of the entry + * + */ + public String getCollectionName() { + return _collectionName; + } + + /** + * + * @param key he key of the value to update + * @param value The value to update + * @return The values of the entry after update + * + * + *

+ * Note: This method is useful if you want to update the value of a specific key. + *

+ * + */ + public EntryData updateValue(String key, Object value) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryUpdatePayload(new EntryData() {{ + put("_id", _entryData.get("_id")); + }}, new EntryData() {{ + put(key, value); + }})).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to update entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return _entryData; + } + + /** + * + * @param entryData The values to update + * @return The values of the entry after update + * + *

+ * Note: This method is useful if you want to update multiple values of the entry. + *

+ * + * + * @see EntryData + * + */ + public EntryData updateValues(EntryData entryData) throws URISyntaxException, IOException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryUpdatePayload(new EntryData() {{ + put("_id", _entryData.get("_id")); + }}, entryData)).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to update entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + + return _entryData; + } + + /** + * + * Deletes the entry + *

+ * Note: Will delete the entry from the collection. This action cannot be undone. + *

+ * + */ + public void delete() throws IOException, URISyntaxException { + URL url = new URI("https://api.marcsync.dev/v1/entries/" + _collectionName).toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("DELETE"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("authorization", _accessToken); + connection.setRequestProperty("content-type", "application/json"); + connection.setDoOutput(true); + + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(_mapper.writeValueAsString(new EntryFilterPayload(new EntryData() {{ + put("_id", _entryData.get("_id")); + }})).getBytes(StandardCharsets.UTF_8)); + } + + if (connection.getResponseCode() != 200) { + throw new IOException("Failed to delete entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/java/MarcSync/classes/CollectionUpdatePayload.java b/src/main/java/MarcSync/classes/CollectionUpdatePayload.java new file mode 100644 index 0000000..e7282a4 --- /dev/null +++ b/src/main/java/MarcSync/classes/CollectionUpdatePayload.java @@ -0,0 +1,9 @@ +package MarcSync.classes; + +public class CollectionUpdatePayload { + public String collectionName; + + public CollectionUpdatePayload(String collectionName) { + this.collectionName = collectionName; + } +} diff --git a/src/main/java/MarcSync/classes/EntryData.java b/src/main/java/MarcSync/classes/EntryData.java new file mode 100644 index 0000000..0452992 --- /dev/null +++ b/src/main/java/MarcSync/classes/EntryData.java @@ -0,0 +1,11 @@ +package MarcSync.classes; + +import com.google.gson.Gson; + +import java.util.HashMap; + +public class EntryData extends HashMap { + public static EntryData fromJson(String json) { + return new Gson().fromJson(json, EntryData.class); + } +} \ No newline at end of file diff --git a/src/main/java/MarcSync/classes/EntryDataPayload.java b/src/main/java/MarcSync/classes/EntryDataPayload.java new file mode 100644 index 0000000..d2781f1 --- /dev/null +++ b/src/main/java/MarcSync/classes/EntryDataPayload.java @@ -0,0 +1,9 @@ +package MarcSync.classes; + +public class EntryDataPayload { + public EntryData data; + + public EntryDataPayload(EntryData entryData) { + this.data = entryData; + } +} diff --git a/src/main/java/MarcSync/classes/EntryFilterPayload.java b/src/main/java/MarcSync/classes/EntryFilterPayload.java new file mode 100644 index 0000000..d25639c --- /dev/null +++ b/src/main/java/MarcSync/classes/EntryFilterPayload.java @@ -0,0 +1,9 @@ +package MarcSync.classes; + +public class EntryFilterPayload { + public EntryData filters; + + public EntryFilterPayload(EntryData entryData) { + this.filters = entryData; + } +} diff --git a/src/main/java/MarcSync/classes/EntryResponse.java b/src/main/java/MarcSync/classes/EntryResponse.java new file mode 100644 index 0000000..f5cc37a --- /dev/null +++ b/src/main/java/MarcSync/classes/EntryResponse.java @@ -0,0 +1,5 @@ +package MarcSync.classes; + +public class EntryResponse { + public EntryData[] entries; +} \ No newline at end of file diff --git a/src/main/java/MarcSync/classes/EntryUpdatePayload.java b/src/main/java/MarcSync/classes/EntryUpdatePayload.java new file mode 100644 index 0000000..1b1843a --- /dev/null +++ b/src/main/java/MarcSync/classes/EntryUpdatePayload.java @@ -0,0 +1,11 @@ +package MarcSync.classes; + +public class EntryUpdatePayload { + public EntryData filters; + public EntryData data; + + public EntryUpdatePayload(EntryData filters, EntryData data) { + this.filters = filters; + this.data = data; + } +} \ No newline at end of file