From e878f43b328fe12dcbac806234bcd8b52b41f17b Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 17 Aug 2021 05:32:05 +0200 Subject: [PATCH] extensionstore models and repository --- .../extensionstore/GExtensionStore.java | 5 + .../extensionstore/repository/StoreFetch.java | 4 + .../repository/StoreRepository.java | 107 ++++++++ .../repository/models/ExtCategory.java | 26 ++ .../repository/models/ExtFramework.java | 47 ++++ .../repository/models/StoreData.java | 29 +++ .../repository/models/StoreExtension.java | 229 ++++++++++++++++++ .../querying/ExtensionOrdering.java | 21 ++ 8 files changed, 468 insertions(+) create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/GExtensionStore.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreFetch.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreRepository.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtCategory.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtFramework.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreData.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreExtension.java create mode 100644 G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/GExtensionStore.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/GExtensionStore.java new file mode 100644 index 0000000..c9541a8 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/GExtensionStore.java @@ -0,0 +1,5 @@ +package gearth.services.internal_extensions.extensionstore; + +public class GExtensionStore { + +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreFetch.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreFetch.java new file mode 100644 index 0000000..dd93474 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreFetch.java @@ -0,0 +1,4 @@ +package gearth.services.internal_extensions.extensionstore.repository; + +public class StoreFetch { +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreRepository.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreRepository.java new file mode 100644 index 0000000..c73d643 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/StoreRepository.java @@ -0,0 +1,107 @@ +package gearth.services.internal_extensions.extensionstore.repository; + +import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory; +import gearth.services.internal_extensions.extensionstore.repository.models.ExtFramework; +import gearth.services.internal_extensions.extensionstore.repository.models.StoreData; +import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension; +import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering; + +import java.util.*; +import java.util.stream.Collectors; + +public class StoreRepository { + + private final StoreData storeData; + + public StoreRepository(StoreData storeData) { + this.storeData = storeData; + } + + public List getCategories() { + return storeData.getCategories(); + } + + public List getFrameworks() { + return storeData.getFrameworks(); + } + + public List getExtensions() { + return storeData.getExtensions(); + } + + public List getExtensions(int offset, int length, String queryString, + ExtensionOrdering ordering, List filterOSes, + List filterClients, List filterFrameworks, + List filterCategories, boolean inverse) { + + String queryLower = queryString.toLowerCase(); + + return getExtensions().stream() + .filter(ext -> ext.getTitle().toLowerCase().contains(queryLower) || ext.getDescription().toLowerCase().contains(queryLower) + || ext.getAuthors().stream().anyMatch(author -> author.getName().toLowerCase().contains(queryLower) + || author.getUsername() != null && author.getUsername().toLowerCase().contains(queryLower)) + || ext.getCategories().stream().anyMatch(extCategory -> extCategory.getName().toLowerCase().contains(queryLower)) + || ext.getFramework().getFramework().getName().toLowerCase().contains(queryLower) + || ext.getLanguage().toLowerCase().contains(queryLower) + || ext.getCompatibility().getSystems().stream().anyMatch(s -> s.toLowerCase().contains(queryLower)) + || ext.getCompatibility().getClients().stream().anyMatch(s -> s.toLowerCase().contains(queryLower))) + .filter(ext -> ext.getCompatibility().getSystems().stream().anyMatch(filterOSes::contains)) + .filter(ext -> ext.getCompatibility().getClients().stream().anyMatch(filterClients::contains)) + .filter(ext -> filterFrameworks.contains(ext.getFramework().getFramework().getName())) + .filter(ext -> ext.getCategories().stream().anyMatch(c -> filterCategories.contains(c.getName()))) + .sorted((o1, o2) -> { + int result = 0; + if (ordering == ExtensionOrdering.RATING) result = -Integer.compare(o1.getRating(), o2.getRating()); + else if (ordering == ExtensionOrdering.LAST_UPDATED) result = -o1.getUpdateDate().compareTo(o2.getUpdateDate()); + else if (ordering == ExtensionOrdering.NEW_RELEASES) result = -o1.getSubmissionDate().compareTo(o2.getSubmissionDate()); + else if (ordering == ExtensionOrdering.ALPHABETICAL) result = o1.getTitle().toLowerCase().compareTo(o2.getTitle().toLowerCase()); + return inverse ? -result : result; + }) + .skip(offset) + .limit(length) + .collect(Collectors.toList()); + } + + public List getOperatingSystems() { + return Arrays.asList("Linux", "Windows", "Mac"); + } + + public List getClients() { + return Arrays.asList("Unity", "Flash"); + } + + public List getLanguages() { + Set languages = new HashSet<>(); + storeData.getFrameworks().forEach(extFramework -> languages.addAll(extFramework.getLanguages())); + return new ArrayList<>(languages); + } + + public List getAuthors() { + Map allAuthors = new HashMap<>(); + storeData.getExtensions().forEach((extension) -> { + extension.getAuthors().forEach(author -> { + if (!allAuthors.containsKey(author.getName())) { + allAuthors.put(author.getName(), author); + } + else { + StoreExtension.Author old = allAuthors.get(author.getName()); + if ((old.getHotel() == null || old.getUsername() == null) && + author.getHotel() != null && author.getUsername() != null) { + allAuthors.put(author.getName(), author); + } + } + }); + }); + + return new ArrayList<>(allAuthors.values()); + } + + public List getOrderings() { + return Arrays.asList(ExtensionOrdering.values()); + } +} + + + + + diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtCategory.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtCategory.java new file mode 100644 index 0000000..1daa1b2 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtCategory.java @@ -0,0 +1,26 @@ +package gearth.services.internal_extensions.extensionstore.repository.models; + +public class ExtCategory { + + private final String name; + private final String description; + private final String icon; + + public ExtCategory(String name, String description, String icon) { + this.name = name; + this.description = description; + this.icon = icon; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getIcon() { + return icon; + } +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtFramework.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtFramework.java new file mode 100644 index 0000000..7ef267a --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/ExtFramework.java @@ -0,0 +1,47 @@ +package gearth.services.internal_extensions.extensionstore.repository.models; + +import java.util.List; + +public class ExtFramework { + + private final String name; + private final List developers; + private final List languages; + private final String source; + + private final boolean installationRequired; + private final String installationInstructions; + + public ExtFramework(String name, List developers, List languages, String source, boolean installationRequired, String installationInstructions) { + this.name = name; + this.developers = developers; + this.languages = languages; + this.source = source; + this.installationRequired = installationRequired; + this.installationInstructions = installationInstructions; + } + + public String getName() { + return name; + } + + public List getDevelopers() { + return developers; + } + + public List getLanguages() { + return languages; + } + + public String getSource() { + return source; + } + + public boolean isInstallationRequired() { + return installationRequired; + } + + public String getInstallationInstructions() { + return installationInstructions; + } +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreData.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreData.java new file mode 100644 index 0000000..e79b213 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreData.java @@ -0,0 +1,29 @@ +package gearth.services.internal_extensions.extensionstore.repository.models; + +import java.util.List; + +public class StoreData { + + private final List categories; + private final List frameworks; + + private final List extensions; + + public StoreData(List categories, List frameworks, List extensions) { + this.categories = categories; + this.frameworks = frameworks; + this.extensions = extensions; + } + + public List getCategories() { + return categories; + } + + public List getFrameworks() { + return frameworks; + } + + public List getExtensions() { + return extensions; + } +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreExtension.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreExtension.java new file mode 100644 index 0000000..6ddba8b --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/models/StoreExtension.java @@ -0,0 +1,229 @@ +package gearth.services.internal_extensions.extensionstore.repository.models; + +import java.time.LocalDateTime; +import java.util.List; + +public class StoreExtension { + + public StoreExtension(String title, String description, List authors, String version, List categories, String source, String readme, boolean stable, Framework framework, String language, Commands commands, Compatibility compatibility, LocalDateTime submissionDate, LocalDateTime updateDate, boolean isOutdated, int rating) { + this.title = title; + this.description = description; + this.authors = authors; + this.version = version; + this.categories = categories; + this.source = source; + this.readme = readme; + this.stable = stable; + this.framework = framework; + this.language = language; + this.commands = commands; + this.compatibility = compatibility; + this.submissionDate = submissionDate; + this.updateDate = updateDate; + this.isOutdated = isOutdated; + this.rating = rating; + } + + public static class Author { + + private final String name; + private final String discord; + private final String hotel; + private final String username; + + private final int extensionsCount; + private final int reputation; + + public Author(String name, String discord, String hotel, String username, int extensionsCount, int reputation) { + this.name = name; + this.discord = discord; + this.hotel = hotel; + this.username = username; + this.extensionsCount = extensionsCount; + this.reputation = reputation; + } + + public String getName() { + return name; + } + + public String getDiscord() { + return discord; + } + + public String getHotel() { + return hotel; + } + + public String getUsername() { + return username; + } + + public int getExtensionsCount() { + return extensionsCount; + } + + public int getReputation() { + return reputation; + } + } + + public static class Framework { + + private final ExtFramework framework; + private final String version; + + public Framework(ExtFramework framework, String version) { + this.framework = framework; + this.version = version; + } + + public ExtFramework getFramework() { + return framework; + } + + public String getVersion() { + return version; + } + } + + public static class Commands { + private final String defaultCommand; + private final String linux; + private final String windows; + private final String mac; + + public Commands(String defaultCommand, String linux, String windows, String mac) { + this.defaultCommand = defaultCommand; + this.linux = linux; + this.windows = windows; + this.mac = mac; + } + + public String getDefault() { + return defaultCommand; + } + + public String getLinux() { + return linux; + } + + public String getWindows() { + return windows; + } + + public String getMac() { + return mac; + } + } + + public static class Compatibility { + private final List systems; + private final List clients; + + public Compatibility(List systems, List clients) { + this.systems = systems; + this.clients = clients; + } + + public List getSystems() { + return systems; + } + + public List getClients() { + return clients; + } + } + + + + private final String title; + private final String description; + + private final List authors; + private final String version; + private final List categories; + + private final String source; + private final String readme; + + private final boolean stable; + + private final Framework framework; + private final String language; + private final Commands commands; + + private final Compatibility compatibility; + + private final LocalDateTime submissionDate; + private final LocalDateTime updateDate; + + private final boolean isOutdated; + + private final int rating; + + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public List getAuthors() { + return authors; + } + + public String getVersion() { + return version; + } + + public List getCategories() { + return categories; + } + + public String getSource() { + return source; + } + + public String getReadme() { + return readme; + } + + public boolean isStable() { + return stable; + } + + public Framework getFramework() { + return framework; + } + + public String getLanguage() { + return language; + } + + public Commands getCommands() { + return commands; + } + + public Compatibility getCompatibility() { + return compatibility; + } + + public LocalDateTime getSubmissionDate() { + return submissionDate; + } + + public LocalDateTime getUpdateDate() { + return updateDate; + } + + public boolean isOutdated() { + return isOutdated; + } + + public int getRating() { + return rating; + } +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java new file mode 100644 index 0000000..dd4be02 --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java @@ -0,0 +1,21 @@ +package gearth.services.internal_extensions.extensionstore.repository.querying; + +public enum ExtensionOrdering { + + RATING("Rating"), + ALPHABETICAL("Alphabetical"), + LAST_UPDATED("Last updated"), + NEW_RELEASES("New releases"); + + + + private String orderName; + + ExtensionOrdering(String orderName) { + this.orderName = orderName; + } + + public String getOrderName() { + return orderName; + } +}