parse pluginBackendResponse to pluginCenterDto / add Endpoint / remove groupId + artefactId from plugins

This commit is contained in:
Eduard Heimbuch
2019-07-26 13:04:54 +02:00
parent 1ea2bdfedf
commit 27dc47a590
15 changed files with 217 additions and 157 deletions

View File

@@ -4,6 +4,7 @@ import com.google.inject.Inject;
import de.otto.edison.hal.Embedded;
import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Links;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginWrapper;
import java.util.Collection;
@@ -24,7 +25,12 @@ public class PluginDtoCollectionMapper {
this.mapper = mapper;
}
public HalRepresentation map(Collection<PluginWrapper> plugins) {
public HalRepresentation map(List<PluginWrapper> plugins) {
List<PluginDto> dtos = plugins.stream().map(mapper::map).collect(toList());
return new HalRepresentation(createLinks(), embedDtos(dtos));
}
public HalRepresentation map(Collection<PluginInformation> plugins) {
List<PluginDto> dtos = plugins.stream().map(mapper::map).collect(toList());
return new HalRepresentation(createLinks(), embedDtos(dtos));
}

View File

@@ -1,6 +1,7 @@
package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Links;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginWrapper;
import javax.inject.Inject;
@@ -16,16 +17,20 @@ public class PluginDtoMapper {
}
public PluginDto map(PluginWrapper plugin) {
return map(plugin.getPlugin().getInformation());
}
public PluginDto map(PluginInformation pluginInformation) {
Links.Builder linksBuilder = linkingTo()
.self(resourceLinks.plugin()
.self(plugin.getPlugin().getInformation().getId(false)));
.self(pluginInformation.getName()));
PluginDto pluginDto = new PluginDto(linksBuilder.build());
pluginDto.setName(plugin.getPlugin().getInformation().getName());
pluginDto.setType(plugin.getPlugin().getInformation().getCategory() != null ? plugin.getPlugin().getInformation().getCategory() : "Miscellaneous");
pluginDto.setVersion(plugin.getPlugin().getInformation().getVersion());
pluginDto.setAuthor(plugin.getPlugin().getInformation().getAuthor());
pluginDto.setDescription(plugin.getPlugin().getInformation().getDescription());
pluginDto.setName(pluginInformation.getName());
pluginDto.setCategory(pluginInformation.getCategory() != null ? pluginInformation.getCategory() : "Miscellaneous");
pluginDto.setVersion(pluginInformation.getVersion());
pluginDto.setAuthor(pluginInformation.getAuthor());
pluginDto.setDescription(pluginInformation.getDescription());
return pluginDto;
}

View File

@@ -4,7 +4,10 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginCenter;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.PluginPermissions;
import sonia.scm.plugin.PluginWrapper;
import sonia.scm.web.VndMediaType;
@@ -16,6 +19,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -27,12 +31,14 @@ public class PluginResource {
private final PluginLoader pluginLoader;
private final PluginDtoCollectionMapper collectionMapper;
private final PluginDtoMapper mapper;
private final PluginManager pluginManager;
@Inject
public PluginResource(PluginLoader pluginLoader, PluginDtoCollectionMapper collectionMapper, PluginDtoMapper mapper) {
public PluginResource(PluginLoader pluginLoader, PluginDtoCollectionMapper collectionMapper, PluginDtoMapper mapper, PluginCenter pluginCenter1, PluginManager pluginManager) {
this.pluginLoader = pluginLoader;
this.collectionMapper = collectionMapper;
this.mapper = mapper;
this.pluginManager = pluginManager;
}
/**
@@ -74,7 +80,7 @@ public class PluginResource {
PluginPermissions.read().check();
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
.stream()
.filter(plugin -> id.equals(plugin.getPlugin().getInformation().getId(false)))
.filter(plugin -> id.equals(plugin.getPlugin().getInformation().getName(false)))
.map(mapper::map)
.findFirst();
if (pluginDto.isPresent()) {
@@ -84,4 +90,23 @@ public class PluginResource {
}
}
/**
* Returns a collection of available plugins.
*
* @return collection of available plugins.
*/
@GET
@Path("/available")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(CollectionDto.class)
@Produces(VndMediaType.PLUGIN_COLLECTION)
public Response getAvailablePlugins() {
PluginPermissions.read().check();
Collection<PluginInformation> plugins = pluginManager.getAvailable();
return Response.ok(collectionMapper.map(plugins)).build();
}
}