git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-publishing/gCat-Feeder-Suite@178654 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a17e6756fe
commit
321eacfd38
|
@ -1,5 +1,9 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.utils;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
|
||||
public class TokenUtils {
|
||||
|
@ -11,4 +15,9 @@ public class TokenUtils {
|
|||
public static String getCurrentToken() {
|
||||
return SecurityTokenProvider.instance.get();
|
||||
}
|
||||
|
||||
public static String getClientId(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
return entry.getClientInfo().getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,11 @@ public class GCatFeeder extends ResourceConfig{
|
|||
registerClasses(Capabilities.class);
|
||||
}
|
||||
|
||||
|
||||
public GCatFeeder(AbstractBinder binder) {
|
||||
super();
|
||||
register(binder);
|
||||
registerClasses(Executions.class);
|
||||
registerClasses(Capabilities.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ public class ServiceConstants {
|
|||
|
||||
public static final String COLLECTOR_ID_PARAMETER="collector";
|
||||
public static final String CATALOGUE_ID_PARAMETER="collector";
|
||||
|
||||
public static final String DEFAULT_VALUE="ALL";
|
||||
}
|
||||
|
||||
public static interface Capabilities{
|
||||
|
|
|
@ -45,12 +45,18 @@ public class Executions {
|
|||
|
||||
try {
|
||||
ExecutionRequest request=new ExecutionRequest();
|
||||
for(String collector:info.getQueryParameters().get(ServiceConstants.Executions.COLLECTOR_ID_PARAMETER))
|
||||
request.addCollectorId(collector);
|
||||
if(info.getQueryParameters().containsKey(ServiceConstants.Executions.COLLECTOR_ID_PARAMETER))
|
||||
for(String collector:info.getQueryParameters().get(ServiceConstants.Executions.COLLECTOR_ID_PARAMETER))
|
||||
request.addCollectorId(collector);
|
||||
else request.addCollectorId(ServiceConstants.Executions.DEFAULT_VALUE);
|
||||
|
||||
|
||||
if(info.getQueryParameters().containsKey(ServiceConstants.Executions.CATALOGUE_ID_PARAMETER))
|
||||
for(String catalogue:info.getQueryParameters().get(ServiceConstants.Executions.CATALOGUE_ID_PARAMETER))
|
||||
request.addCollectorId(catalogue);
|
||||
|
||||
request.addControllerId(catalogue);
|
||||
else request.addControllerId(ServiceConstants.Executions.DEFAULT_VALUE);
|
||||
|
||||
|
||||
log.trace("Submitting request {} ",request);
|
||||
|
||||
return engine.submit(request);
|
||||
|
|
|
@ -5,6 +5,17 @@ import java.sql.SQLException;
|
|||
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.ExecutionManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.FeederEngine;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.CatalogueControllersManagerImpl;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.CollectorsManagerImpl;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.ExecutionManagerImpl;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.FeederEngineImpl;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.mockups.PersistenceManagerMock;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
@ -20,7 +31,18 @@ public class BaseTest extends JerseyTest{
|
|||
@Override
|
||||
protected Application configure() {
|
||||
|
||||
return new GCatFeeder();
|
||||
AbstractBinder binder = new AbstractBinder() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(FeederEngineImpl.class).to(FeederEngine.class);
|
||||
bind(CatalogueControllersManagerImpl.class).to(CatalogueControllersManager.class);
|
||||
bind(CollectorsManagerImpl.class).to(CollectorsManager.class);
|
||||
bind(ExecutionManagerImpl.class).to(ExecutionManager.class);
|
||||
bind(PersistenceManagerMock.class).to(PersistenceManager.class);
|
||||
}
|
||||
};
|
||||
|
||||
return new GCatFeeder(binder);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExecutionsTest extends BaseTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void getAll() {
|
||||
WebTarget target=
|
||||
target(ServiceConstants.Executions.PATH);
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().get();
|
||||
System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
if(resp.getStatus()!=200) throw new RuntimeException("GetAll error should never happen");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submitALLAndPoll() {
|
||||
WebTarget target=
|
||||
target(ServiceConstants.Executions.PATH);
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().post(Entity.json(""));
|
||||
System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
// if(resp.getStatus()!=200) throw new RuntimeException("GetAll error should never happen");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongSubmission() {
|
||||
WebTarget target=
|
||||
target(ServiceConstants.Executions.PATH).
|
||||
queryParam(ServiceConstants.Executions.CATALOGUE_ID_PARAMETER, TestCommon.FAKE_CATALOGUE_ID+"_NOT");
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().post(Entity.json(""));
|
||||
if(resp.getStatus()!=400) throw new RuntimeException("Expected ERROR STATUS 400 BUT received "+resp.getStatus());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.mockups;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionStatus;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError;
|
||||
|
||||
@Singleton
|
||||
public class PersistenceManagerMock implements PersistenceManager {
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor create(ExecutionRequest request) throws PersistenceError, InvalidRequest {
|
||||
return getEquivalent(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound, InvalidRequest {
|
||||
if(theMap.containsKey(id))
|
||||
return theMap.get(id);
|
||||
else throw new ElementNotFound("Unable to find request with id "+id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter)
|
||||
throws PersistenceError, InvalidRequest {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(ExecutionDescriptor toUpdate) throws PersistenceError, ElementNotFound {
|
||||
if(theMap.containsKey(toUpdate.getId())) {
|
||||
theMap.replace(toUpdate.getId(), toUpdate);
|
||||
return true;
|
||||
}
|
||||
else throw new ElementNotFound("Unable to find request with id "+toUpdate.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acquire(String id) throws PersistenceError, ElementNotFound {
|
||||
theMap.computeIfPresent(id, BiFunction<String, ExecutionDescriptor, ExecutionDescriptor> bi = (x,y) ->{
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Actuall persistence in map
|
||||
|
||||
private ConcurrentHashMap<String,ExecutionDescriptor> theMap=new ConcurrentHashMap<>();
|
||||
|
||||
private ExecutionDescriptor getEquivalent(ExecutionRequest req) {
|
||||
ExecutionDescriptor toReturn=new ExecutionDescriptor();
|
||||
toReturn.setCallerContext("TEST");
|
||||
toReturn.setCallerIdentity("TESTER");
|
||||
toReturn.setCallerEncryptedToken("TEST");
|
||||
|
||||
toReturn.setCatalogues(req.getToInvokeControllers());
|
||||
toReturn.setCollectors(req.getToInvokeCollectors());
|
||||
|
||||
toReturn.setId(UUID.randomUUID().toString());
|
||||
|
||||
toReturn.setStatus(ExecutionStatus.PENDING);
|
||||
theMap.put(toReturn.getId(), toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue