Plugins REST Interface
This commit is contained in:
parent
630815050a
commit
3849990e98
|
@ -11,8 +11,10 @@ public class InterfaceConstants {
|
|||
|
||||
public static final class Methods{
|
||||
public static final String UCD ="ucd";
|
||||
public static final String SECTIONS="sections";
|
||||
public static final String PROJECTS="projects";
|
||||
public static final String PLUGINS="plugins";
|
||||
|
||||
|
||||
|
||||
|
||||
public static final String CONCESSIONI="concessioni";
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
|||
import org.gcube.application.geoportal.service.rest.ConcessioniOverMongo;
|
||||
|
||||
|
||||
import org.gcube.application.geoportal.service.rest.Plugins;
|
||||
import org.gcube.application.geoportal.service.rest.ProfiledDocuments;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.service.rest.UseCaseDescriptors;
|
||||
|
@ -42,8 +43,8 @@ public class GeoPortalService extends ResourceConfig{
|
|||
|
||||
registerClasses(ConcessioniOverMongo.class);
|
||||
registerClasses(ProfiledDocuments.class);
|
||||
|
||||
registerClasses(UseCaseDescriptors.class);
|
||||
registerClasses(Plugins.class);
|
||||
|
||||
log.info("Setting implementations .. ");
|
||||
|
||||
|
|
|
@ -1,9 +1,55 @@
|
|||
package org.gcube.application.geoportal.service.rest;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache;
|
||||
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Path(InterfaceConstants.Methods.PLUGINS)
|
||||
@Slf4j
|
||||
public class Plugins {
|
||||
|
||||
// get status (configuration + report)
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<PluginDescriptor> getDescriptor(){
|
||||
return new GuardedMethod<List<PluginDescriptor>>(){
|
||||
@Override
|
||||
protected List<PluginDescriptor> run() throws Exception, WebApplicationException {
|
||||
List<PluginDescriptor> toReturn=new ArrayList<>();
|
||||
ImplementationProvider.get().getEngineByManagedClass(PluginManager.PluginMap.class).
|
||||
forEach((s, plugin) -> {try {
|
||||
toReturn.add(plugin.getDescriptor());
|
||||
}catch (Throwable t){ log.error("Unable to get Descriptor for {}",s,t);}});
|
||||
return toReturn;
|
||||
}
|
||||
}.execute().getResult();
|
||||
}
|
||||
|
||||
// force reinitialization
|
||||
@GET
|
||||
@Path("{pluginID}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public PluginDescriptor getDescriptorByID(@PathParam("pluginID") String pluginID){
|
||||
return new GuardedMethod<PluginDescriptor>(){
|
||||
@Override
|
||||
protected PluginDescriptor run() throws Exception, WebApplicationException {
|
||||
Map<String, Plugin> m=ImplementationProvider.get().getEngineByManagedClass(PluginManager.PluginMap.class);
|
||||
if(m.containsKey(pluginID))
|
||||
return m.get(pluginID).getDescriptor();
|
||||
else throw new WebApplicationException("Plugin \""+pluginID+"\" not found", Response.Status.NOT_FOUND);
|
||||
}
|
||||
}.execute().getResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue