2017-05-17 16:45:38 +02:00
|
|
|
package org.gcube.data.transfer.service.transfers;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
import javax.ws.rs.Path;
|
2017-12-05 18:18:13 +01:00
|
|
|
import javax.ws.rs.PathParam;
|
2017-05-17 16:45:38 +02:00
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
2017-12-05 18:18:13 +01:00
|
|
|
import javax.ws.rs.core.Response;
|
2017-05-17 16:45:38 +02:00
|
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
|
|
|
|
import org.gcube.data.transfer.model.ServiceConstants;
|
|
|
|
import org.gcube.data.transfer.model.TransferCapabilities;
|
2017-12-13 15:04:13 +01:00
|
|
|
import org.gcube.data.transfer.service.DTServiceAppManager;
|
2017-05-17 16:45:38 +02:00
|
|
|
import org.gcube.data.transfer.service.transfers.engine.CapabilitiesProvider;
|
2017-12-05 18:18:13 +01:00
|
|
|
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
|
|
|
|
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
|
2017-12-13 15:04:13 +01:00
|
|
|
import org.gcube.smartgears.annotations.ManagedBy;
|
2017-05-17 16:45:38 +02:00
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Path(ServiceConstants.CAPABILTIES_SERVLET_NAME)
|
2017-12-13 15:04:13 +01:00
|
|
|
@ManagedBy(DTServiceAppManager.class)
|
2017-05-17 16:45:38 +02:00
|
|
|
public class Capabilities {
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
CapabilitiesProvider provider;
|
|
|
|
|
2017-12-13 15:04:13 +01:00
|
|
|
|
|
|
|
PluginManager plugins=PluginManager.get();
|
2017-05-17 16:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public TransferCapabilities getCapabilities(){
|
|
|
|
log.debug("Serving get capabilities");
|
|
|
|
try{
|
|
|
|
TransferCapabilities toReturn=provider.get();
|
|
|
|
log.debug("No exceptions here.. returning "+toReturn);
|
|
|
|
return toReturn;
|
|
|
|
}catch(Exception e){
|
|
|
|
log.debug("Unable to return capabilities.",e);
|
|
|
|
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 18:18:13 +01:00
|
|
|
@GET
|
|
|
|
@Path("pluginInfo/{pluginId}")
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Response getPluginInfo(@PathParam("pluginId") String pluginID) {
|
|
|
|
log.trace("Getting plugin info for plugin ID : {} ",pluginID);
|
|
|
|
try{
|
|
|
|
return Response.ok(plugins.getPluginInfo(pluginID),MediaType.APPLICATION_JSON).build();
|
|
|
|
}catch(PluginNotFoundException e) {
|
|
|
|
throw new WebApplicationException("Plugin "+pluginID+" has not been found",Status.NOT_FOUND);
|
|
|
|
}catch(Throwable t) {
|
|
|
|
throw new WebApplicationException("Unexpected error. ",t,Status.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 16:45:38 +02:00
|
|
|
}
|