Fixing use cases
This commit is contained in:
parent
9b253621b3
commit
bd86648161
|
@ -11,6 +11,7 @@ import org.gcube.application.geoportal.common.rest.Projects;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
@ -47,9 +48,18 @@ public class ClearProjects {
|
||||||
|
|
||||||
ExecutorService service = Executors.newFixedThreadPool(1);
|
ExecutorService service = Executors.newFixedThreadPool(1);
|
||||||
|
|
||||||
|
ConcurrentSkipListSet<String> ids = new ConcurrentSkipListSet<>();
|
||||||
|
|
||||||
|
// it.forEachRemaining(project -> ids.add(project.getId()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it.forEachRemaining((Project c)->{
|
it.forEachRemaining((Project c)->{
|
||||||
found.incrementAndGet();
|
System.out.println("Found ID "+c.getId()+" N° "+found.incrementAndGet());
|
||||||
|
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -75,9 +85,9 @@ public class ClearProjects {
|
||||||
}catch(Throwable throwable){
|
}catch(Throwable throwable){
|
||||||
System.err.println(throwable);
|
System.err.println(throwable);
|
||||||
errors.add(c.getId());
|
errors.add(c.getId());
|
||||||
try {Thread.sleep(1000);} catch (InterruptedException i) {}
|
// try {Thread.sleep(1000);} catch (InterruptedException i) {}
|
||||||
}finally{
|
}finally{
|
||||||
count.incrementAndGet();
|
System.out.println("Handled N "+count.incrementAndGet()+" concessioni");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,8 +6,12 @@ import org.bson.Document;
|
||||||
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
|
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
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.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.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.rest.TempFile;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
|
||||||
import org.gcube.application.geoportal.common.rest.Projects;
|
import org.gcube.application.geoportal.common.rest.Projects;
|
||||||
|
@ -20,6 +24,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.rmi.RemoteException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
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
|
// read from imported folder
|
||||||
// File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1652276569045");
|
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/Documents/Work/GNA DATA/Bug_23378");
|
||||||
String targetContext="/gcube/devsec/devVRE";
|
String targetContext="/gcube/devsec/devVRE";
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +60,7 @@ public class ExportConcessioniAsProjects {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<Concessione> found=new ArrayList<>();
|
ArrayList<Concessione> found=new ArrayList<>();
|
||||||
for(File elementFolder:dir.listFiles()){
|
for(File elementFolder:dir.listFiles()){
|
||||||
if(elementFolder.isFile()&&elementFolder.getName().endsWith(".json"))
|
if(elementFolder.isFile()&&elementFolder.getName().endsWith(".json"))
|
||||||
|
@ -94,18 +100,17 @@ public class ExportConcessioniAsProjects {
|
||||||
|
|
||||||
System.out.println("Completed "+count.get()+" [elapsedTime = "+(System.currentTimeMillis()-startProcess)/1000+" sec] [warn : "+warnCount.get()+", err : "+errCount.get()+"]");
|
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){
|
private static void publish(Concessione c, Projects<Project> client, AtomicLong errCount,AtomicLong count){
|
||||||
|
@ -139,6 +144,13 @@ public class ExportConcessioniAsProjects {
|
||||||
// CREATE Project
|
// CREATE Project
|
||||||
Project project = client.createNew(doc);
|
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
|
// Relazione
|
||||||
if(c.getRelazioneScavo()!=null) {
|
if(c.getRelazioneScavo()!=null) {
|
||||||
RelazioneScavo rel=c.getRelazioneScavo();
|
RelazioneScavo rel=c.getRelazioneScavo();
|
||||||
|
@ -156,10 +168,8 @@ public class ExportConcessioniAsProjects {
|
||||||
req = FileSets.build("$." + ProfiledConcessione.RELAZIONE_SCAVO, "fileset",
|
req = FileSets.build("$." + ProfiledConcessione.RELAZIONE_SCAVO, "fileset",
|
||||||
"$." + ProfiledConcessione.RELAZIONE_SCAVO + "." + Field.CHILDREN
|
"$." + ProfiledConcessione.RELAZIONE_SCAVO + "." + Field.CHILDREN
|
||||||
+ "[?(@.fileset)]");
|
+ "[?(@.fileset)]");
|
||||||
req.addAll(content.stream().
|
req.addAll(convertFiles(content));
|
||||||
filter(p -> p instanceof WorkspaceContent)
|
req.setAccess(getAccess(rel));
|
||||||
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
||||||
}
|
}
|
||||||
// upload fileset
|
// upload fileset
|
||||||
|
@ -217,10 +227,8 @@ public class ExportConcessioniAsProjects {
|
||||||
req = FileSets.build("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE+"["+i+"]", "fileset",
|
req = FileSets.build("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE+"["+i+"]", "fileset",
|
||||||
"$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE + "." + Field.CHILDREN
|
"$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE + "." + Field.CHILDREN
|
||||||
+ "[?(@.fileset)]");
|
+ "[?(@.fileset)]");
|
||||||
req.addAll(content.stream().
|
req.addAll(convertFiles(content));
|
||||||
filter(p -> p instanceof WorkspaceContent)
|
req.setAccess(getAccess(img));
|
||||||
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,10 +259,8 @@ public class ExportConcessioniAsProjects {
|
||||||
req = FileSets.build("$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO, "fileset",
|
req = FileSets.build("$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO, "fileset",
|
||||||
"$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO + "." + Field.CHILDREN
|
"$." + ProfiledConcessione.POSIZIONAMENTO_SCAVO + "." + Field.CHILDREN
|
||||||
+ "[?(@.fileset)]");
|
+ "[?(@.fileset)]");
|
||||||
req.addAll(content.stream().
|
req.addAll(convertFiles(content));
|
||||||
filter(p -> p instanceof WorkspaceContent)
|
req.setAccess(getAccess(l));
|
||||||
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
||||||
}
|
}
|
||||||
// upload fileset
|
// upload fileset
|
||||||
|
@ -286,21 +292,22 @@ public class ExportConcessioniAsProjects {
|
||||||
|
|
||||||
// FileSets
|
// FileSets
|
||||||
for (int i = 0; i < c.getPianteFineScavo().size(); i++) {
|
for (int i = 0; i < c.getPianteFineScavo().size(); i++) {
|
||||||
LayerConcessione img=c.getPianteFineScavo().get(i);
|
LayerConcessione layerConcessione=c.getPianteFineScavo().get(i);
|
||||||
List<PersistedContent> content=img.getActualContent();
|
List<PersistedContent> content=layerConcessione.getActualContent();
|
||||||
if(content!=null && !content.isEmpty()) {
|
if(content!=null && !content.isEmpty()) {
|
||||||
req = FileSets.build("$." + ProfiledConcessione.PIANTE_FINE_SCAVO+"["+i+"]", "fileset",
|
req = FileSets.build("$." + ProfiledConcessione.PIANTE_FINE_SCAVO+"["+i+"]", "fileset",
|
||||||
"$." + ProfiledConcessione.PIANTE_FINE_SCAVO + "." + Field.CHILDREN
|
"$." + ProfiledConcessione.PIANTE_FINE_SCAVO + "." + Field.CHILDREN
|
||||||
+ "[?(@.fileset)]");
|
+ "[?(@.fileset)]");
|
||||||
req.addAll(content.stream().
|
req.addAll(convertFiles(content));
|
||||||
filter(p -> p instanceof WorkspaceContent)
|
req.setAccess(getAccess(layerConcessione));
|
||||||
.map(p -> new TempFile(null, ((WorkspaceContent) p).getLink(), ((WorkspaceContent) p).getName()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
project = client.registerFileSet(project.getId(),req.getTheRequest());
|
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");
|
System.out.println("Done "+c.getId()+" in "+(System.currentTimeMillis()-startTime)/1000+" sec");
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
System.err.println(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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue