Exposed method Unpublish

This commit is contained in:
Fabio Sinibaldi 2021-08-03 16:24:00 +02:00
parent 9dc3fd4588
commit 93b3b9a9c0
4 changed files with 83 additions and 12 deletions

View File

@ -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<WebTarget,String>(){
@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<Concessione> getList() throws Exception {
public Iterator<Concessione> getList() throws Exception {
log.debug("Getting list");
Call<WebTarget,Iterable<Concessione>> call=new Call<WebTarget,Iterable<Concessione>>(){
Call<WebTarget,Iterator<Concessione>> call=new Call<WebTarget,Iterator<Concessione>>(){
@Override
public Iterable<Concessione> call(WebTarget endpoint) throws Exception {
public Iterator<Concessione> call(WebTarget endpoint) throws Exception {
Iterable<Concessione> toReturn=new ArrayList<Concessione>();
return (Iterable<Concessione>) mapper.readerFor(Concessione.class).readValues(
MappingIterator<Concessione> iterator=mapper.readerFor(Concessione.class).readValues(
endpoint.request(MediaType.APPLICATION_JSON).get(InputStream.class));
return iterator;
}
};
return delegate.make(call);

View File

@ -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<WebTarget,String> call= new Call<WebTarget, String>() {
//
// @Override
@ -36,10 +41,10 @@ public class DefaultProjects implements ProjectsI{
}
@Override
public Iterable<Project> getAll() throws RemoteException {
Call<WebTarget,Iterable<Project>> call=new Call<WebTarget,Iterable<Project>>(){
public Iterator<Project> getAll() throws RemoteException {
Call<WebTarget,Iterator<Project>> call=new Call<WebTarget,Iterator<Project>>(){
@Override
public Iterable<Project> call(WebTarget endpoint) throws Exception {
public Iterator<Project> call(WebTarget endpoint) throws Exception {
throw new Exception("Client method not ready");
}
};
@ -51,13 +56,13 @@ public class DefaultProjects implements ProjectsI{
}
@Override
public Iterable<Project> getByFilter(String filter) throws RemoteException {
public Iterator<Project> getByFilter(String filter) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<Project> getByFilter(String filter, String profileId) throws RemoteException {
public Iterator<Project> 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<Project> getByProfile(String profileId) throws RemoteException {
public Iterator<Project> getByProfile(String profileId) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

View File

@ -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");
}

View File

@ -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<String> 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()+"]");
}
}