mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
cleanup / fix endpoints
This commit is contained in:
@@ -5,11 +5,9 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
|||||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||||
import sonia.scm.plugin.Plugin;
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginInformation;
|
import sonia.scm.plugin.PluginInformation;
|
||||||
import sonia.scm.plugin.PluginLoader;
|
|
||||||
import sonia.scm.plugin.PluginManager;
|
import sonia.scm.plugin.PluginManager;
|
||||||
import sonia.scm.plugin.PluginPermissions;
|
import sonia.scm.plugin.PluginPermissions;
|
||||||
import sonia.scm.plugin.PluginState;
|
import sonia.scm.plugin.PluginState;
|
||||||
import sonia.scm.plugin.PluginWrapper;
|
|
||||||
import sonia.scm.web.VndMediaType;
|
import sonia.scm.web.VndMediaType;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -19,9 +17,7 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -74,7 +70,7 @@ public class AvailablePluginResource {
|
|||||||
@ResponseCode(code = 200, condition = "success"),
|
@ResponseCode(code = 200, condition = "success"),
|
||||||
@ResponseCode(code = 500, condition = "internal server error")
|
@ResponseCode(code = 500, condition = "internal server error")
|
||||||
})
|
})
|
||||||
@TypeHint(CollectionDto.class)
|
@TypeHint(PluginDto.class)
|
||||||
@Produces(VndMediaType.PLUGIN)
|
@Produces(VndMediaType.PLUGIN)
|
||||||
public Response getAvailablePlugin(@PathParam("name") String name, @PathParam("version") String version) {
|
public Response getAvailablePlugin(@PathParam("name") String name, @PathParam("version") String version) {
|
||||||
PluginPermissions.read().check();
|
PluginPermissions.read().check();
|
||||||
@@ -82,12 +78,17 @@ public class AvailablePluginResource {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(p -> p.getId().equals(name + ":" + version))
|
.filter(p -> p.getId().equals(name + ":" + version))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
return Response.ok(dtoMapper.map(plugin.get())).build();
|
if (plugin.isPresent()) {
|
||||||
|
return Response.ok(plugin.get()).build();
|
||||||
|
} else {
|
||||||
|
throw notFound(entity(Plugin.class, name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 200 when plugin installation is successful triggered.
|
* Triggers plugin installation.
|
||||||
*
|
* @param name plugin artefact name
|
||||||
|
* @param version plugin version
|
||||||
* @return HTTP Status.
|
* @return HTTP Status.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@@ -96,8 +97,6 @@ public class AvailablePluginResource {
|
|||||||
@ResponseCode(code = 200, condition = "success"),
|
@ResponseCode(code = 200, condition = "success"),
|
||||||
@ResponseCode(code = 500, condition = "internal server error")
|
@ResponseCode(code = 500, condition = "internal server error")
|
||||||
})
|
})
|
||||||
@TypeHint(CollectionDto.class)
|
|
||||||
@Produces(VndMediaType.PLUGIN)
|
|
||||||
public Response installPlugin(@PathParam("name") String name, @PathParam("version") String version) {
|
public Response installPlugin(@PathParam("name") String name, @PathParam("version") String version) {
|
||||||
PluginPermissions.manage().check();
|
PluginPermissions.manage().check();
|
||||||
pluginManager.install(name + ":" + version);
|
pluginManager.install(name + ":" + version);
|
||||||
|
|||||||
@@ -4,27 +4,21 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
|||||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||||
import sonia.scm.plugin.Plugin;
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginCenter;
|
|
||||||
import sonia.scm.plugin.PluginInformation;
|
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.plugin.PluginManager;
|
import sonia.scm.plugin.PluginManager;
|
||||||
import sonia.scm.plugin.PluginPermissions;
|
import sonia.scm.plugin.PluginPermissions;
|
||||||
import sonia.scm.plugin.PluginState;
|
|
||||||
import sonia.scm.plugin.PluginWrapper;
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
import sonia.scm.web.VndMediaType;
|
import sonia.scm.web.VndMediaType;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||||
import static sonia.scm.NotFoundException.notFound;
|
import static sonia.scm.NotFoundException.notFound;
|
||||||
@@ -66,12 +60,12 @@ public class InstalledPluginResource {
|
|||||||
/**
|
/**
|
||||||
* Returns the installed plugin with the given id.
|
* Returns the installed plugin with the given id.
|
||||||
*
|
*
|
||||||
* @param id id of plugin
|
* @param name name of plugin
|
||||||
*
|
*
|
||||||
* @return installed plugin with specified id
|
* @return installed plugin with specified id
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}")
|
@Path("/{name}")
|
||||||
@StatusCodes({
|
@StatusCodes({
|
||||||
@ResponseCode(code = 200, condition = "success"),
|
@ResponseCode(code = 200, condition = "success"),
|
||||||
@ResponseCode(code = 404, condition = "not found"),
|
@ResponseCode(code = 404, condition = "not found"),
|
||||||
@@ -79,17 +73,17 @@ public class InstalledPluginResource {
|
|||||||
})
|
})
|
||||||
@TypeHint(PluginDto.class)
|
@TypeHint(PluginDto.class)
|
||||||
@Produces(VndMediaType.PLUGIN)
|
@Produces(VndMediaType.PLUGIN)
|
||||||
public Response getInstalledPlugin(@PathParam("id") String id) {
|
public Response getInstalledPlugin(@PathParam("name") String name) {
|
||||||
PluginPermissions.read().check();
|
PluginPermissions.read().check();
|
||||||
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
|
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(plugin -> id.equals(plugin.getPlugin().getInformation().getName(false)))
|
.filter(plugin -> name.equals(plugin.getPlugin().getInformation().getName()))
|
||||||
.map(mapper::map)
|
.map(mapper::map)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (pluginDto.isPresent()) {
|
if (pluginDto.isPresent()) {
|
||||||
return Response.ok(pluginDto.get()).build();
|
return Response.ok(pluginDto.get()).build();
|
||||||
} else {
|
} else {
|
||||||
throw notFound(entity(Plugin.class, id));
|
throw notFound(entity(Plugin.class, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user