diff --git a/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java b/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java index 5effc2127..751e19667 100644 --- a/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java +++ b/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java @@ -26,16 +26,16 @@ public class VersionUpload { // @el(root: String) @NotBlank(message = "version.new.error.channel.noName") - private final @Validate(SpEL = "@validate.regex(#root, @hangarConfig.channels.nameRegex)", message = "channel.modal.error.invalidName") String channelName; + private final @Validate(SpEL = "@validate.regex(#root, @hangarConfig.channels.nameRegex)", message = "channel.modal.error.invalidName") String channel; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public VersionUpload(final String versionString, final Map> pluginDependencies, final EnumMap> platformDependencies, final String description, final List files, final String channelName) { + public VersionUpload(final String versionString, final Map> pluginDependencies, final EnumMap> platformDependencies, final String description, final List files, final String channel) { this.versionString = versionString; this.pluginDependencies = pluginDependencies; this.platformDependencies = platformDependencies; this.description = description; this.files = files; - this.channelName = channelName; + this.channel = channel; } public String getVersionString() { @@ -58,8 +58,8 @@ public class VersionUpload { return this.files; } - public String getChannelName() { - return this.channelName; + public String getChannel() { + return this.channel; } public PendingVersion toPendingVersion(final List files) { @@ -68,7 +68,7 @@ public class VersionUpload { (EnumMap>) this.platformDependencies, this.description, files, - this.channelName, + this.channel, null, null, false @@ -83,7 +83,7 @@ public class VersionUpload { ", platformDependencies=" + this.platformDependencies + ", description='" + this.description + '\'' + ", files=" + this.files + - ", channelName='" + this.channelName + '\'' + + ", channelName='" + this.channel + '\'' + '}'; } } diff --git a/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java b/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java index 6afc85ec5..fe23a1d8a 100644 --- a/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java +++ b/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java @@ -48,7 +48,7 @@ public class VersionsApiService extends HangarComponent { } // TODO Do the upload in one step - final PendingVersion preparedPendingVersion = this.versionFactory.createPendingVersion(project.getId(), versionUpload.getFiles(), files, versionUpload.getChannelName(), false); + final PendingVersion preparedPendingVersion = this.versionFactory.createPendingVersion(project.getId(), versionUpload.getFiles(), files, versionUpload.getChannel(), false); final PendingVersion pendingVersion = versionUpload.toPendingVersion(preparedPendingVersion.getFiles()); this.versionFactory.publishPendingVersion(project.getId(), pendingVersion); } diff --git a/backend/src/main/java/io/papermc/hangar/service/internal/versions/VersionFactory.java b/backend/src/main/java/io/papermc/hangar/service/internal/versions/VersionFactory.java index 0f27b23f0..a7ec69b5d 100644 --- a/backend/src/main/java/io/papermc/hangar/service/internal/versions/VersionFactory.java +++ b/backend/src/main/java/io/papermc/hangar/service/internal/versions/VersionFactory.java @@ -55,7 +55,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.SortedSet; import java.util.stream.Collectors; @@ -304,6 +303,8 @@ public class VersionFactory extends HangarComponent { // cache purging this.projectService.refreshHomeProjects(); this.usersApiService.clearAuthorsCache(); + } catch (final HangarApiException e) { + throw e; } catch (final Exception e) { this.logger.error("Unable to create version {} for {}", pendingVersion.getVersionString(), this.getHangarPrincipal().getName(), e); if (projectVersionTable != null) { @@ -344,11 +345,11 @@ public class VersionFactory extends HangarComponent { for (final PluginDependency pluginDependency : platformListEntry.getValue()) { Long depProjectId = null; if (pluginDependency.getNamespace() != null) { - final Optional depProjectTable = Optional.ofNullable(this.projectService.getProjectTable(pluginDependency.getNamespace().getOwner(), pluginDependency.getNamespace().getSlug())); - if (depProjectTable.isEmpty()) { + final ProjectTable depProjectTable = this.projectService.getProjectTable(pluginDependency.getNamespace().getOwner(), pluginDependency.getNamespace().getSlug()); + if (depProjectTable == null) { throw new HangarApiException(HttpStatus.BAD_REQUEST, "version.new.error.invalidPluginDependencyNamespace"); } - depProjectId = depProjectTable.get().getProjectId(); + depProjectId = depProjectTable.getProjectId(); } pluginDependencyTables.add(new ProjectVersionDependencyTable(versionId, platformListEntry.getKey(), pluginDependency.getName(), pluginDependency.isRequired(), depProjectId, pluginDependency.getExternalUrl())); }