diff --git a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultDocumentsClient.java b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultDocumentsClient.java index 57a7688..2e2b74b 100644 --- a/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultDocumentsClient.java +++ b/geoportal-client/src/main/java/org/gcube/application/geoportal/client/DefaultDocumentsClient.java @@ -8,6 +8,7 @@ import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.configuration.Configuration; +import org.gcube.application.geoportal.common.model.document.access.Access; import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest; @@ -231,10 +232,54 @@ public class DefaultDocumentsClient implements Projects { } } + @Override + public T forceUnlock(String id) throws RemoteException { + try { + log.warn("Force Unlock of {} [useCaseDescriptor {} , class {}]", + id, profileID,getManagedClass()); + Call call = endpoint -> { + return ResponseCommons.check(endpoint.path(profileID).path(InterfaceConstants.Methods.FORCE_UNLOCK).path(id). + request(MediaType.APPLICATION_JSON). + put(Entity.json("")),getManagedClass()); + }; + T toReturn=delegate.make(call); + log.info("Unlocked ID {} useCaseDescriptor {}", id, profileID); + return toReturn; + }catch(RemoteException e){ + log.error("Unexpected error ",e); + throw e; + }catch(Exception e){ + log.error("Unexpected error ",e); + throw new RemoteException("Unexpected Error", e); + } + } + + @Override + public T setAccessPolicy(String id, Access toSet) throws RemoteException { + try { + log.info("Setting Access of {} [useCaseDescriptor {} , class {}] as {}", + id, profileID,getManagedClass(),toSet); + Call call = endpoint -> { + return ResponseCommons.check(endpoint.path(profileID).path(InterfaceConstants.Methods.SET_PROJECT_ACCESS_POLICY).path(id). + request(MediaType.APPLICATION_JSON). + put(Entity.json(toSet)),getManagedClass()); + }; + T toReturn=delegate.make(call); + log.debug("Updated Access of ID {} useCaseDescriptor {}", id, profileID); + return toReturn; + }catch(RemoteException e){ + log.error("Unexpected error ",e); + throw e; + }catch(Exception e){ + log.error("Unexpected error ",e); + throw new RemoteException("Unexpected Error", e); + } + } + @Override public T updateDocument(String id, Document updatedDocument) throws RemoteException { try { - log.debug("Updateing {}  [useCaseDescriptor {}  , class {}] with ", + log.debug("Updateing {} [useCaseDescriptor {} , class {}] with ", id, profileID,getManagedClass(),updatedDocument); Call call = endpoint -> { return ResponseCommons.check(endpoint.path(profileID).path(id). @@ -242,7 +287,7 @@ public class DefaultDocumentsClient implements Projects { put(Entity.entity(updatedDocument, MediaType.APPLICATION_JSON)),getManagedClass()); }; T toReturn=delegate.make(call); - log.info("Updated ID {}  useCaseDescriptor {}  ", id, profileID); + log.info("Updated ID {} useCaseDescriptor {}", id, profileID); return toReturn; }catch(RemoteException e){ log.error("Unexpected error ",e); diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/Projects.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/Projects.java index 467269c..c09faf5 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/Projects.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/Projects.java @@ -4,6 +4,7 @@ import org.bson.Document; import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.configuration.Configuration; +import org.gcube.application.geoportal.common.model.document.access.Access; import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest; @@ -39,4 +40,7 @@ public interface Projects

{ public P registerFileSet(String id, RegisterFileSetRequest req) throws RemoteException, InvalidRequestException; //FileSets public P deleteFileSet(String id, String path, Boolean force) throws RemoteException; + + public P forceUnlock(String id) throws RemoteException; + public P setAccessPolicy(String id, Access toSet) throws RemoteException; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java index 09e64ee..1816a7c 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java @@ -683,10 +683,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< // expected exception toUnlock = getByID(id); }finally { - if(toUnlock!=null) unlock(toUnlock); + if(toUnlock!=null) + return unlock(toUnlock); else throw new WebApplicationException("Unable to get Project "+id, Response.Status.EXPECTATION_FAILED); } - return null; } @Override diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java index aac65f6..8f91642 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java @@ -87,7 +87,7 @@ public class UserUtils { user.setRoles(roles); }catch(Exception e){ log.warn("Unable to determine user id, using FAKE",e); - user.setUsername("FAKE"); + user.setUsername("fabio.sinibaldi"); user.setRoles(new HashSet<>()); user.getRoles().addAll(DEFAULT_ROLES); } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java index baf1d21..c745372 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java @@ -20,6 +20,7 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -105,6 +106,19 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{ return doc; } + @Test + public void testUnlock() throws Exception { + assumeTrue(GCubeTest.isTestInfrastructureEnabled()); + // Not automatic, needs generation of locked project + assumeTrue(false); + String id = "627e87bb02ad3d1a2e0e9e18"; + String ucd = "profiledConcessioni"; + Project p =check(target(InterfaceConstants.Methods.PROJECTS).path(ucd).path(InterfaceConstants.Methods.FORCE_UNLOCK).path(id).request(MediaType.APPLICATION_JSON). + put(Entity.entity("", MediaType.APPLICATION_JSON)), Project.class); + assertNull(p.getLock()); + } + + // @Test // public void testSDI() throws Exception { // // Create new diff --git a/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearProjects.java b/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearProjects.java index 942e33c..85ebcd1 100644 --- a/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearProjects.java +++ b/use-cases/src/test/java/org/gcube/application/cms/usecases/ClearProjects.java @@ -11,9 +11,7 @@ import org.gcube.application.geoportal.common.rest.Projects; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Iterator; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicLong; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects; @@ -38,14 +36,16 @@ public class ClearProjects { AtomicLong count=new AtomicLong(0); AtomicLong nullCount=new AtomicLong(0); - AtomicLong errCount=new AtomicLong(0); + + ConcurrentSkipListSet errors = new ConcurrentSkipListSet<>(); + AtomicLong found=new AtomicLong(0); Iterator it=null; it=client.query(new QueryRequest()); // it=manager.search("{\"nome\" : {$regex : \"Mock .*\"}, \"creationTime\" :{$gt : \"2021-10-18T13:58:53.326\"}}"); - ExecutorService service = Executors.newFixedThreadPool(3); + ExecutorService service = Executors.newFixedThreadPool(1); it.forEachRemaining((Project c)->{ @@ -60,6 +60,11 @@ public class ClearProjects { System.out.println("ID IS NULL " + c); nullCount.incrementAndGet(); } + if(c.getLock()!=null){ + System.out.println("Unlocking "+currentId); + client.forceUnlock(currentId); + } + else if(toSkipIds.contains(currentId)) System.out.println("Skipping "+currentId); @@ -69,7 +74,7 @@ public class ClearProjects { } }catch(Throwable throwable){ System.err.println(throwable); - errCount.incrementAndGet(); + errors.add(c.getId()); try {Thread.sleep(1000);} catch (InterruptedException i) {} }finally { count.incrementAndGet(); @@ -83,8 +88,10 @@ public class ClearProjects { if(found.get()==count.get()) service.shutdown(); } - System.out.println("Done "+count.get()+" [null : "+nullCount.get()+", err : "+errCount.get()+"]"); + System.out.println("Done "+count.get()+" [null : "+nullCount.get()+", err : "+errors.size()+"]"); + System.out.println("Errors : "); + errors.forEach(s -> System.out.println(s)); } }