mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
extensionstore models and repository
This commit is contained in:
parent
3d81e07838
commit
e878f43b32
@ -0,0 +1,5 @@
|
||||
package gearth.services.internal_extensions.extensionstore;
|
||||
|
||||
public class GExtensionStore {
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package gearth.services.internal_extensions.extensionstore.repository;
|
||||
|
||||
public class StoreFetch {
|
||||
}
|
@ -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<ExtCategory> getCategories() {
|
||||
return storeData.getCategories();
|
||||
}
|
||||
|
||||
public List<ExtFramework> getFrameworks() {
|
||||
return storeData.getFrameworks();
|
||||
}
|
||||
|
||||
public List<StoreExtension> getExtensions() {
|
||||
return storeData.getExtensions();
|
||||
}
|
||||
|
||||
public List<StoreExtension> getExtensions(int offset, int length, String queryString,
|
||||
ExtensionOrdering ordering, List<String> filterOSes,
|
||||
List<String> filterClients, List<String> filterFrameworks,
|
||||
List<String> 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<String> getOperatingSystems() {
|
||||
return Arrays.asList("Linux", "Windows", "Mac");
|
||||
}
|
||||
|
||||
public List<String> getClients() {
|
||||
return Arrays.asList("Unity", "Flash");
|
||||
}
|
||||
|
||||
public List<String> getLanguages() {
|
||||
Set<String> languages = new HashSet<>();
|
||||
storeData.getFrameworks().forEach(extFramework -> languages.addAll(extFramework.getLanguages()));
|
||||
return new ArrayList<>(languages);
|
||||
}
|
||||
|
||||
public List<StoreExtension.Author> getAuthors() {
|
||||
Map<String, StoreExtension.Author> 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<ExtensionOrdering> getOrderings() {
|
||||
return Arrays.asList(ExtensionOrdering.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<String> developers;
|
||||
private final List<String> languages;
|
||||
private final String source;
|
||||
|
||||
private final boolean installationRequired;
|
||||
private final String installationInstructions;
|
||||
|
||||
public ExtFramework(String name, List<String> developers, List<String> 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<String> getDevelopers() {
|
||||
return developers;
|
||||
}
|
||||
|
||||
public List<String> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public boolean isInstallationRequired() {
|
||||
return installationRequired;
|
||||
}
|
||||
|
||||
public String getInstallationInstructions() {
|
||||
return installationInstructions;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StoreData {
|
||||
|
||||
private final List<ExtCategory> categories;
|
||||
private final List<ExtFramework> frameworks;
|
||||
|
||||
private final List<StoreExtension> extensions;
|
||||
|
||||
public StoreData(List<ExtCategory> categories, List<ExtFramework> frameworks, List<StoreExtension> extensions) {
|
||||
this.categories = categories;
|
||||
this.frameworks = frameworks;
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
public List<ExtCategory> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public List<ExtFramework> getFrameworks() {
|
||||
return frameworks;
|
||||
}
|
||||
|
||||
public List<StoreExtension> getExtensions() {
|
||||
return extensions;
|
||||
}
|
||||
}
|
@ -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<Author> authors, String version, List<ExtCategory> 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<String> systems;
|
||||
private final List<String> clients;
|
||||
|
||||
public Compatibility(List<String> systems, List<String> clients) {
|
||||
this.systems = systems;
|
||||
this.clients = clients;
|
||||
}
|
||||
|
||||
public List<String> getSystems() {
|
||||
return systems;
|
||||
}
|
||||
|
||||
public List<String> getClients() {
|
||||
return clients;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
private final List<Author> authors;
|
||||
private final String version;
|
||||
private final List<ExtCategory> 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<Author> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public List<ExtCategory> 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user