Fixing use cases

This commit is contained in:
Fabio Sinibaldi 2022-06-08 18:12:11 +02:00
parent 9b253621b3
commit bd86648161
2 changed files with 74 additions and 36 deletions

View File

@ -11,6 +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.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
@ -47,9 +48,18 @@ public class ClearProjects {
ExecutorService service = Executors.newFixedThreadPool(1);
ConcurrentSkipListSet<String> ids = new ConcurrentSkipListSet<>();
// it.forEachRemaining(project -> ids.add(project.getId()));
it.forEachRemaining((Project c)->{
found.incrementAndGet();
System.out.println("Found ID "+c.getId()+""+found.incrementAndGet());
service.submit(new Runnable() {
@Override
public void run() {
@ -75,9 +85,9 @@ public class ClearProjects {
}catch(Throwable throwable){
System.err.println(throwable);
errors.add(c.getId());
try {Thread.sleep(1000);} catch (InterruptedException i) {}
}finally {
count.incrementAndGet();
// try {Thread.sleep(1000);} catch (InterruptedException i) {}
}finally{
System.out.println("Handled N "+count.incrementAndGet()+" concessioni");
}
}
});

View File

@ -6,8 +6,12 @@ import org.bson.Document;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
import org.gcube.application.geoportal.common.rest.Projects;
@ -20,6 +24,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
@ -44,10 +49,10 @@ public class ExportConcessioniAsProjects {
}
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) throws InterruptedException, RemoteException {
// read from imported folder
// File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1652276569045");
File dir = new File("/Users/fabioisti/Documents/Work/GNA DATA/Bug_23378");
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1652276569045");
// File dir = new File("/Users/fabioisti/Documents/Work/GNA DATA/Bug_23378");
String targetContext="/gcube/devsec/devVRE";
@ -55,6 +60,7 @@ public class ExportConcessioniAsProjects {
ArrayList<Concessione> found=new ArrayList<>();
for(File elementFolder:dir.listFiles()){
if(elementFolder.isFile()&&elementFolder.getName().endsWith(".json"))
@ -94,20 +100,19 @@ public class ExportConcessioniAsProjects {
System.out.println("Completed "+count.get()+" [elapsedTime = "+(System.currentTimeMillis()-startProcess)/1000+" sec] [warn : "+warnCount.get()+", err : "+errCount.get()+"]");
Configuration conf = client.getConfiguration();
conf.getArchives().stream().forEach(archive -> {
if (archive.getType().equals("DOCUMENT-STORE-COLLECTION")){
archive.forEach((s, o) ->{
System.out.println(s+"\t:\t"+o);
});
}
});
}
// public static List<TempFile> upload(List<PersistedContent> contents,StorageUtils storage) throws IOException {
// ArrayList toReturn = new ArrayList();
// for (PersistedContent content : contents)
// if (content instanceof WorkspaceContent) {
// WorkspaceContent wc = (WorkspaceContent) content;
// toReturn.add(storage.putOntoStorage(new URL(wc.getLink()).openStream(), wc.getName()));
// }
// return toReturn;
// }
private static void publish(Concessione c, Projects<Project> client, AtomicLong errCount,AtomicLong count){
try {
long startTime = System.currentTimeMillis();
@ -139,6 +144,13 @@ public class ExportConcessioniAsProjects {
// CREATE Project
Project project = client.createNew(doc);
// set Access
Access toSetAccess = new Access();
toSetAccess.setPolicy(AccessPolicy.valueOf(c.getPolicy().toString()));
toSetAccess.setLicense(c.getLicenzaID());
project = client.setAccessPolicy(project.getId(),toSetAccess);
// Relazione
if(c.getRelazioneScavo()!=null) {
RelazioneScavo rel=c.getRelazioneScavo();
@ -156,10 +168,8 @@ public class ExportConcessioniAsProjects {
req = FileSets.build("$." + ProfiledConcessione.RELAZIONE_SCAVO, "fileset",
"$." + ProfiledConcessione.RELAZIONE_SCAVO + "." + Field.CHILDREN
+ "[?(@.fileset)]");
req.addAll(content.stream().
filter(p -> p instanceof WorkspaceContent)
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
.collect(Collectors.toList()));
req.addAll(convertFiles(content));
req.setAccess(getAccess(rel));
project = client.registerFileSet(project.getId(),req.getTheRequest());
}
// upload fileset
@ -217,10 +227,8 @@ public class ExportConcessioniAsProjects {
req = FileSets.build("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE+"["+i+"]", "fileset",
"$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE + "." + Field.CHILDREN
+ "[?(@.fileset)]");
req.addAll(content.stream().
filter(p -> p instanceof WorkspaceContent)
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
.collect(Collectors.toList()));
req.addAll(convertFiles(content));
req.setAccess(getAccess(img));
project = client.registerFileSet(project.getId(),req.getTheRequest());
}
}
@ -251,10 +259,8 @@ public class ExportConcessioniAsProjects {
req = FileSets.build("$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO, "fileset",
"$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO + "." + Field.CHILDREN
+ "[?(@.fileset)]");
req.addAll(content.stream().
filter(p -> p instanceof WorkspaceContent)
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
.collect(Collectors.toList()));
req.addAll(convertFiles(content));
req.setAccess(getAccess(l));
project = client.registerFileSet(project.getId(),req.getTheRequest());
}
// upload fileset
@ -286,21 +292,22 @@ public class ExportConcessioniAsProjects {
// FileSets
for (int i = 0; i < c.getPianteFineScavo().size(); i++) {
LayerConcessione img=c.getPianteFineScavo().get(i);
List<PersistedContent> content=img.getActualContent();
LayerConcessione layerConcessione=c.getPianteFineScavo().get(i);
List<PersistedContent> content=layerConcessione.getActualContent();
if(content!=null && !content.isEmpty()) {
req = FileSets.build("$." + ProfiledConcessione.PIANTE_FINE_SCAVO+"["+i+"]", "fileset",
"$." + ProfiledConcessione.PIANTE_FINE_SCAVO + "." + Field.CHILDREN
+ "[?(@.fileset)]");
req.addAll(content.stream().
filter(p -> p instanceof WorkspaceContent)
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
.collect(Collectors.toList()));
req.addAll(convertFiles(content));
req.setAccess(getAccess(layerConcessione));
project = client.registerFileSet(project.getId(),req.getTheRequest());
}
}
}
// Submit for review
project = client.performStep(project.getId(),step());
System.out.println("Done "+c.getId()+" in "+(System.currentTimeMillis()-startTime)/1000+" sec");
} catch (Throwable throwable) {
System.err.println(throwable);
@ -310,4 +317,25 @@ public class ExportConcessioniAsProjects {
}
}
private static final List<TempFile> convertFiles(List<PersistedContent> content){
return content.stream().
filter(p -> p instanceof WorkspaceContent)
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
.collect(Collectors.toList());
}
private static final Access getAccess(AssociatedContent content){
Access toReturn = new Access();
toReturn.setLicense(content.getLicenseID());
toReturn.setPolicy(AccessPolicy.valueOf(content.getPolicy().toString()));
return toReturn;
}
private static final StepExecutionRequest step(){
StepExecutionRequest toReturn = new StepExecutionRequest();
toReturn.setStepID("SUBMIT-FOR-REVIEW");
return toReturn;
}
}