|
|
|
@ -1,16 +1,18 @@
|
|
|
|
|
package org.gcube.data.spd.resources;
|
|
|
|
|
|
|
|
|
|
import static org.gcube.data.streams.dsl.Streams.convert;
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.AuthorizedTasks;
|
|
|
|
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
|
|
|
|
import org.gcube.data.spd.exception.MaxRetriesReachedException;
|
|
|
|
|
import org.gcube.data.spd.manager.AppInitializer;
|
|
|
|
|
import org.gcube.data.spd.manager.OccurrenceWriterManager;
|
|
|
|
@ -19,6 +21,7 @@ import org.gcube.data.spd.model.exceptions.ExternalRepositoryException;
|
|
|
|
|
import org.gcube.data.spd.model.exceptions.IdNotValidException;
|
|
|
|
|
import org.gcube.data.spd.model.exceptions.StreamBlockingException;
|
|
|
|
|
import org.gcube.data.spd.model.products.OccurrencePoint;
|
|
|
|
|
import org.gcube.data.spd.model.service.types.MultiLocatorResponse;
|
|
|
|
|
import org.gcube.data.spd.plugin.PluginManager;
|
|
|
|
|
import org.gcube.data.spd.plugin.fwk.AbstractPlugin;
|
|
|
|
|
import org.gcube.data.spd.plugin.fwk.capabilities.OccurrencesCapability;
|
|
|
|
@ -28,12 +31,12 @@ import org.gcube.data.spd.plugin.fwk.writers.Writer;
|
|
|
|
|
import org.gcube.data.spd.plugin.fwk.writers.rswrapper.AbstractWrapper;
|
|
|
|
|
import org.gcube.data.spd.plugin.fwk.writers.rswrapper.LocalWrapper;
|
|
|
|
|
import org.gcube.data.spd.plugin.fwk.writers.rswrapper.ResultWrapper;
|
|
|
|
|
import org.gcube.data.spd.utils.DynamicMap;
|
|
|
|
|
import org.gcube.data.spd.utils.ExecutorsContainer;
|
|
|
|
|
import org.gcube.data.spd.utils.QueryRetryCall;
|
|
|
|
|
import org.gcube.data.spd.utils.ResultWrapperMantainer;
|
|
|
|
|
import org.gcube.data.spd.utils.VOID;
|
|
|
|
|
import org.gcube.data.streams.Stream;
|
|
|
|
|
import org.gcube.data.streams.dsl.Streams;
|
|
|
|
|
import org.gcube.smartgears.ApplicationManagerProvider;
|
|
|
|
|
import org.gcube.smartgears.ContextProvider;
|
|
|
|
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
|
|
@ -57,16 +60,18 @@ public class Occurrences{
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("keys")
|
|
|
|
|
public Response getByKeys(@QueryParam("keys") List<String> keys) {
|
|
|
|
|
public Response getByKeys() {
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
logger.trace("keys arrived are {} ",keys);
|
|
|
|
|
|
|
|
|
|
Stream<String> reader = Streams.convert(keys.iterator());
|
|
|
|
|
String inputLocatorId = UUID.randomUUID().toString();
|
|
|
|
|
DynamicMap.put(inputLocatorId);
|
|
|
|
|
|
|
|
|
|
logger.trace("locator used as input is {} ",inputLocatorId);
|
|
|
|
|
|
|
|
|
|
Stream<String> reader = convert(DynamicMap.get(inputLocatorId));
|
|
|
|
|
|
|
|
|
|
ResultWrapper<OccurrencePoint> wrapper = ResultWrapperMantainer.getWrapper(OccurrencePoint.class);
|
|
|
|
|
|
|
|
|
|
logger.trace("entering in the getOccurrence by productKeys with keys {}",keys);
|
|
|
|
|
ExecutorsContainer.execJob(AuthorizedTasks.bind(new RunnableOccurrenceSearch(reader, wrapper, ExecType.KEYS)));
|
|
|
|
|
|
|
|
|
|
// the output will be probably returned even before
|
|
|
|
@ -74,9 +79,12 @@ public class Occurrences{
|
|
|
|
|
StringBuilder redirectUri = new StringBuilder();
|
|
|
|
|
redirectUri.append("http://").append(ctx.container().configuration().hostname()).append(":").append(ctx.container().configuration().port());
|
|
|
|
|
redirectUri.append(ctx.application().getContextPath()).append(Constants.APPLICATION_ROOT_PATH).append("/").append(Constants.RESULTSET_PATH).append("/").append(wrapper.getLocator());
|
|
|
|
|
|
|
|
|
|
logger.trace("redirect uri is {} ",redirectUri.toString());
|
|
|
|
|
try{
|
|
|
|
|
return Response.temporaryRedirect(new URI(redirectUri.toString())).build();
|
|
|
|
|
MultiLocatorResponse multiLocatorResponse = new MultiLocatorResponse(wrapper.getLocator(), inputLocatorId, ctx.profile(GCoreEndpoint.class).id());
|
|
|
|
|
logger.trace("retrnign multilocator {}",multiLocatorResponse);
|
|
|
|
|
return Response.temporaryRedirect(new URI(redirectUri.toString())).entity(multiLocatorResponse).build();
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.error("invalid redirect uri created",e);
|
|
|
|
|
return Response.serverError().build();
|
|
|
|
@ -89,9 +97,13 @@ public class Occurrences{
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("ids")
|
|
|
|
|
public Response getByIds(@QueryParam("ids") List<String> ids){
|
|
|
|
|
public Response getByIds(){
|
|
|
|
|
try{
|
|
|
|
|
Stream<String> reader = Streams.convert(ids.iterator());
|
|
|
|
|
|
|
|
|
|
String inputLocatorId = UUID.randomUUID().toString();
|
|
|
|
|
DynamicMap.put(inputLocatorId);
|
|
|
|
|
|
|
|
|
|
Stream<String> reader = convert(DynamicMap.get(inputLocatorId));
|
|
|
|
|
|
|
|
|
|
ResultWrapper<OccurrencePoint> wrapper = ResultWrapperMantainer.getWrapper(OccurrencePoint.class);
|
|
|
|
|
ExecutorsContainer.execJob(AuthorizedTasks.bind(new RunnableOccurrenceSearch(reader, wrapper, ExecType.IDS)));
|
|
|
|
@ -102,7 +114,8 @@ public class Occurrences{
|
|
|
|
|
redirectUri.append(ctx.application().getContextPath()).append(Constants.APPLICATION_ROOT_PATH).append("/").append(Constants.RESULTSET_PATH).append("/").append(wrapper.getLocator());
|
|
|
|
|
logger.trace("redirect uri is {} ",redirectUri.toString());
|
|
|
|
|
try{
|
|
|
|
|
return Response.temporaryRedirect(new URI(redirectUri.toString())).build();
|
|
|
|
|
MultiLocatorResponse multiLocatorResponse = new MultiLocatorResponse(wrapper.getLocator(), inputLocatorId, ctx.profile(GCoreEndpoint.class).id());
|
|
|
|
|
return Response.temporaryRedirect(new URI(redirectUri.toString())).entity(multiLocatorResponse).build();
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.error("invalid redirect uri created",e);
|
|
|
|
|
return Response.serverError().build();
|
|
|
|
|