From 93b3b9a9c03de61562459d1affb20ec27e357fe3 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Tue, 3 Aug 2021 16:24:00 +0200 Subject: [PATCH] Exposed method Unpublish --- .../client/DefaultMongoConcessioni.java | 22 ++++++-- .../geoportal/client/DefaultProjects.java | 17 +++--- .../common/model/StatelessClientTests.java | 2 +- .../geoportal/usecases/ClearConcessioni.java | 54 +++++++++++++++++++ 4 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/gcube/application/geoportal/usecases/ClearConcessioni.java diff --git a/src/main/java/org/gcube/application/geoportal/client/DefaultMongoConcessioni.java b/src/main/java/org/gcube/application/geoportal/client/DefaultMongoConcessioni.java index 03741c6..1ea1082 100644 --- a/src/main/java/org/gcube/application/geoportal/client/DefaultMongoConcessioni.java +++ b/src/main/java/org/gcube/application/geoportal/client/DefaultMongoConcessioni.java @@ -2,12 +2,16 @@ package org.gcube.application.geoportal.client; import java.io.InputStream; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import com.fasterxml.jackson.databind.MappingIterator; +import com.fasterxml.jackson.databind.ObjectReader; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.rest.AddSectionToConcessioneRequest; @@ -49,11 +53,16 @@ public class DefaultMongoConcessioni implements MongoConcessioni{ @Override public void deleteById(String id) throws Exception { + deleteById(id,false); + } + + @Override + public void deleteById(String id,Boolean force) throws Exception { log.debug("Deleting by id {}",id); delegate.make(new Call(){ @Override public String call(WebTarget endpoint) throws Exception { - check(endpoint.path(id).request(MediaType.APPLICATION_JSON).delete(),null); + check(endpoint.path(id).queryParam(InterfaceConstants.Parameters.FORCE,force).request(MediaType.APPLICATION_JSON).delete(),null); log.info("Deleted by id {}",id); return null; } @@ -76,14 +85,17 @@ public class DefaultMongoConcessioni implements MongoConcessioni{ } @Override - public Iterable getList() throws Exception { + public Iterator getList() throws Exception { log.debug("Getting list"); - Call> call=new Call>(){ + Call> call=new Call>(){ @Override - public Iterable call(WebTarget endpoint) throws Exception { + public Iterator call(WebTarget endpoint) throws Exception { Iterable toReturn=new ArrayList(); - return (Iterable) mapper.readerFor(Concessione.class).readValues( + + MappingIterator iterator=mapper.readerFor(Concessione.class).readValues( endpoint.request(MediaType.APPLICATION_JSON).get(InputStream.class)); + + return iterator; } }; return delegate.make(call); diff --git a/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java b/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java index 2fa91d0..37415f2 100644 --- a/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java +++ b/src/main/java/org/gcube/application/geoportal/client/DefaultProjects.java @@ -1,6 +1,7 @@ package org.gcube.application.geoportal.client; import java.rmi.RemoteException; +import java.util.Iterator; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; @@ -21,6 +22,10 @@ public class DefaultProjects implements ProjectsI{ @Override public void deleteById(String profileId, String projectId) throws RemoteException { + deleteById(profileId,projectId,false); + } + @Override + public void deleteById(String profileId, String projectId,Boolean force) throws RemoteException { // Call call= new Call() { // // @Override @@ -36,10 +41,10 @@ public class DefaultProjects implements ProjectsI{ } @Override - public Iterable getAll() throws RemoteException { - Call> call=new Call>(){ + public Iterator getAll() throws RemoteException { + Call> call=new Call>(){ @Override - public Iterable call(WebTarget endpoint) throws Exception { + public Iterator call(WebTarget endpoint) throws Exception { throw new Exception("Client method not ready"); } }; @@ -51,13 +56,13 @@ public class DefaultProjects implements ProjectsI{ } @Override - public Iterable getByFilter(String filter) throws RemoteException { + public Iterator getByFilter(String filter) throws RemoteException { // TODO Auto-generated method stub return null; } @Override - public Iterable getByFilter(String filter, String profileId) throws RemoteException { + public Iterator getByFilter(String filter, String profileId) throws RemoteException { // TODO Auto-generated method stub return null; } @@ -69,7 +74,7 @@ public class DefaultProjects implements ProjectsI{ } @Override - public Iterable getByProfile(String profileId) throws RemoteException { + public Iterator getByProfile(String profileId) throws RemoteException { // TODO Auto-generated method stub return null; } diff --git a/src/test/java/org/gcube/application/geoportal/common/model/StatelessClientTests.java b/src/test/java/org/gcube/application/geoportal/common/model/StatelessClientTests.java index a3cca34..5e68045 100644 --- a/src/test/java/org/gcube/application/geoportal/common/model/StatelessClientTests.java +++ b/src/test/java/org/gcube/application/geoportal/common/model/StatelessClientTests.java @@ -40,7 +40,7 @@ public class StatelessClientTests extends BasicVreTests{ public void testList() throws Exception { final AtomicLong counter=new AtomicLong(); long before=System.currentTimeMillis(); - client.getList().forEach((Concessione c)-> {counter.addAndGet(1);}); + client.getList().forEachRemaining((Concessione c)-> {counter.addAndGet(1);}); System.out.println("Loaded "+counter+" in "+(System.currentTimeMillis()-before)+" ms"); } diff --git a/src/test/java/org/gcube/application/geoportal/usecases/ClearConcessioni.java b/src/test/java/org/gcube/application/geoportal/usecases/ClearConcessioni.java new file mode 100644 index 0000000..76e05ae --- /dev/null +++ b/src/test/java/org/gcube/application/geoportal/usecases/ClearConcessioni.java @@ -0,0 +1,54 @@ +package org.gcube.application.geoportal.usecases; + +import org.gcube.application.geoportal.client.legacy.ConcessioniManager; +import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI; +import org.gcube.application.geoportal.common.model.TokenSetter; +import org.gcube.application.geoportal.common.model.legacy.Concessione; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; + +import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.statefulMongoConcessioni; + +public class ClearConcessioni { + + public static void main(String[] args) throws Exception { + TokenSetter.set("/gcube/devsec/devVRE"); + + ConcessioniManagerI manager=statefulMongoConcessioni().build(); + + + ArrayList toSkipIds=new ArrayList<>(); + toSkipIds.add("6102c8dd02ad3d05b5f81df4"); + toSkipIds.add("610415af02ad3d05b5f81ee3"); + + AtomicLong count=new AtomicLong(0); + AtomicLong nullCount=new AtomicLong(0); + AtomicLong errCount=new AtomicLong(0); + manager.getList().forEachRemaining((Concessione c)->{ + try{ + String currentId=c.getMongo_id(); + if(currentId==null) { + System.out.println("ID IS NULL " + c); + nullCount.incrementAndGet(); + } + else + if(toSkipIds.contains(currentId)) + System.out.println("Skipping "+currentId); + else { + System.out.println("Deleting " + c.getMongo_id()); + manager.deleteById(c.getMongo_id(),true); + } + }catch(Throwable throwable){ + System.err.println(throwable); + errCount.incrementAndGet(); + }finally { + count.incrementAndGet(); + } + }); + + System.out.println("Done "+count.get()+" [null : "+nullCount.get()+", err : "+errCount.get()+"]"); + + } +}