Fix VersionData getFilteredDependencies and isRecommended

This commit is contained in:
KennyTV 2020-08-22 11:06:06 +02:00
parent 710030a5e6
commit 1538fd9738
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 27 additions and 6 deletions

View File

@ -3,10 +3,13 @@ package io.papermc.hangar.model;
import io.papermc.hangar.db.model.ProjectVersionTagsTable;
import io.papermc.hangar.model.generated.Dependency;
import io.papermc.hangar.service.VersionService;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@ -16,6 +19,14 @@ public enum Platform {
WATERFALL("Waterfall", PlatformCategory.PROXY_CATEGORY, 1, "waterfall", TagColor.WATERFALL, "https://papermc.io/downloads#Waterfall"),
VELOCITY("Velocity", PlatformCategory.PROXY_CATEGORY, 1, "velocity", TagColor.VELOCITY, "https://www.velocitypowered.com/downloads");
private static final Map<String, Platform> PLATFORMS_BY_DEPENDENDY = new HashMap<>();
static {
for (Platform platform : values()) {
PLATFORMS_BY_DEPENDENDY.put(platform.dependencyId, platform);
}
}
private final String name;
private final PlatformCategory platformCategory;
private final int priority;
@ -102,6 +113,11 @@ public enum Platform {
.collect(Collectors.toList());
}
@Nullable
public static Platform getByDependencyId(String dependencyId) {
return PLATFORMS_BY_DEPENDENDY.get(dependencyId.toLowerCase());
}
public static List<ProjectVersionTagsTable> createPlatformTags(VersionService versionService, long versionId, List<Dependency> dependencies) {
return versionService.insertTags(getGhostTags(versionId, dependencies));
}

View File

@ -6,12 +6,10 @@ import io.papermc.hangar.db.model.ProjectsTable;
import io.papermc.hangar.model.Platform;
import io.papermc.hangar.model.generated.Dependency;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
public class VersionData {
@ -50,11 +48,18 @@ public class VersionData {
}
public Map<Dependency, ProjectsTable> getFilteredDependencies() {
List<String> platformIds = Arrays.stream(Platform.getValues()).map(Platform::getDependencyId).collect(Collectors.toList());
return dependencies.entrySet().stream().filter(entry -> !platformIds.contains(entry.getKey().getPluginId())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
// Value is nullable, so we can't use Collectors#toMap
Map<Dependency, ProjectsTable> map = new HashMap<>();
for (Entry<Dependency, ProjectsTable> entry : dependencies.entrySet()) {
if (Platform.getByDependencyId(entry.getKey().getPluginId()) == null) { // Exclude the platform dependency
map.put(entry.getKey(), entry.getValue());
}
}
return map;
}
public boolean isRecommended() {
return p.getProject().getRecommendedVersionId() == v.getId();
final Long recommendedVersionId = p.getProject().getRecommendedVersionId();
return recommendedVersionId != null && recommendedVersionId == v.getId();
}
}