Rename channel field, rethrow api exceptions

This commit is contained in:
Nassim Jahnke 2023-01-23 12:56:30 +01:00
parent aa2a72a970
commit 02f0f06365
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 13 additions and 12 deletions

View File

@ -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<Platform, Set<PluginDependency>> pluginDependencies, final EnumMap<Platform, SortedSet<String>> platformDependencies, final String description, final List<MultipartFileOrUrl> files, final String channelName) {
public VersionUpload(final String versionString, final Map<Platform, Set<PluginDependency>> pluginDependencies, final EnumMap<Platform, SortedSet<String>> platformDependencies, final String description, final List<MultipartFileOrUrl> 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<PendingVersionFile> files) {
@ -68,7 +68,7 @@ public class VersionUpload {
(EnumMap<Platform, SortedSet<String>>) 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 + '\'' +
'}';
}
}

View File

@ -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);
}

View File

@ -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<ProjectTable> 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()));
}