Testings
This commit is contained in:
parent
a77616f189
commit
2989a493b9
|
@ -2,6 +2,7 @@ package org.gcube.application.geoportal.clients;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.tests.TestDocuments;
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
|
@ -37,8 +38,8 @@ public abstract class GenericUseCases extends BasicVreTests{
|
|||
public void createNew () throws RemoteException, FileNotFoundException, JsonProcessingException {
|
||||
String profileID=getUCID();
|
||||
|
||||
String myJSON=null;
|
||||
Document myDocument = Document.parse(myJSON);
|
||||
Document myDocument= new Document();
|
||||
myDocument.put("section",new Document("title","myTitle"));
|
||||
|
||||
Projects<Project> client = getClient(profileID);
|
||||
|
||||
|
@ -46,9 +47,9 @@ public abstract class GenericUseCases extends BasicVreTests{
|
|||
Project project = client.createNew(myDocument);
|
||||
|
||||
|
||||
String parentPath = "";
|
||||
String fieldName = "";
|
||||
String fieldDefinition = "";
|
||||
String parentPath = "$.section";
|
||||
String fieldName = "fileset";
|
||||
String fieldDefinition = "$.section._children[?(@.fileset)]";
|
||||
|
||||
// Prepare request
|
||||
RegisterFileSetRequest fsRequest = FileSets.
|
||||
|
|
|
@ -64,7 +64,11 @@ public class FileSets {
|
|||
return this;
|
||||
}
|
||||
|
||||
public RegisterFileSetRequest getTheRequest(){return theRequest;}
|
||||
public RegisterFileSetRequest getTheRequest(){
|
||||
if(theRequest.getClashOption()==null)
|
||||
// default Clash Policy
|
||||
setClashPolicy(RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING);
|
||||
return theRequest;}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPl
|
|||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.statefulMongoConcessioni;
|
||||
|
||||
@Slf4j
|
||||
public class ExportConcessioniAsProfiledDocuments {
|
||||
public class ExportConcessioniAsProjects {
|
||||
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class ExportConcessioniAsProfiledDocuments {
|
|||
|
||||
public static void main(String[] args) {
|
||||
// read from imported folder
|
||||
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1632326294149");
|
||||
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1652276569045");
|
||||
String targetContext="/gcube/devsec/devVRE";
|
||||
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
package org.gcube.application.cms.usecases;
|
||||
|
||||
import ch.qos.logback.core.helpers.ThrowableToStringArray;
|
||||
import ch.qos.logback.core.net.SyslogOutputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.client.legacy.ConcessioniManager;
|
||||
import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;
|
||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.legacy.*;
|
||||
|
@ -13,6 +16,10 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.statefulMongoConcessioni;
|
||||
|
||||
@Slf4j
|
||||
/*
|
||||
|
@ -31,6 +38,8 @@ public class Import {
|
|||
// String sourceContext="/pred4s/preprod/preVRE";
|
||||
|
||||
|
||||
Boolean saveFilesLocally=false;
|
||||
|
||||
|
||||
// GET FOM SOURCE
|
||||
TokenSetter.set(sourceContext);
|
||||
|
@ -38,45 +47,48 @@ public class Import {
|
|||
StorageHubClient sgClient=new StorageHubClient();
|
||||
|
||||
|
||||
// ConcessioniManagerI manager= statefulMongoConcessioni().build();
|
||||
ConcessioniManagerI sourceManager= statefulMongoConcessioni().build();
|
||||
|
||||
ConcessioniManager sourceManager = new ConcessioniManager();
|
||||
ArrayList<Concessione> found=new ArrayList<>();
|
||||
sourceManager.getList().forEach((Concessione c)->{
|
||||
Map<String,String> errors = new HashMap<>();
|
||||
|
||||
|
||||
sourceManager.getList().forEachRemaining(concessione -> found.add(concessione));
|
||||
System.out.println("Loaded "+found.size()+" elements, saving them..");
|
||||
found.forEach((Concessione c)-> {
|
||||
try {
|
||||
File currentFolder=new File (dir.toString(),c.getId()+"");
|
||||
File currentFolder = new File(dir.toString(), c.getMongo_id() + "");
|
||||
currentFolder.mkdirs();
|
||||
|
||||
//Load locally
|
||||
// POSIZIONAMENTO
|
||||
loadFiles(c.getPosizionamentoScavo(),new File(currentFolder,"pos"),sgClient);
|
||||
// RELAZIONE
|
||||
loadFiles(c.getRelazioneScavo(),new File(currentFolder,"rel"),sgClient);
|
||||
// IMGs
|
||||
for(int i=0;i<c.getImmaginiRappresentative().size();i++)
|
||||
loadFiles(c.getImmaginiRappresentative().get(i), new File(currentFolder,"imgs_"+i),sgClient);
|
||||
if(saveFilesLocally) {
|
||||
// POSIZIONAMENTO
|
||||
loadFiles(c.getPosizionamentoScavo(), new File(currentFolder, "pos"), sgClient);
|
||||
// RELAZIONE
|
||||
loadFiles(c.getRelazioneScavo(), new File(currentFolder, "rel"), sgClient);
|
||||
// IMGs
|
||||
for (int i = 0; i < c.getImmaginiRappresentative().size(); i++)
|
||||
loadFiles(c.getImmaginiRappresentative().get(i), new File(currentFolder, "imgs_" + i), sgClient);
|
||||
|
||||
// Piante
|
||||
for(int i=0;i<c.getPianteFineScavo().size();i++)
|
||||
loadFiles(c.getPianteFineScavo().get(i), new File(currentFolder,"pianta_"+i),sgClient);
|
||||
|
||||
found.add(c);
|
||||
|
||||
|
||||
PrintWriter w=new PrintWriter(new File(currentFolder,c.getId()+".json"));
|
||||
// Piante
|
||||
for (int i = 0; i < c.getPianteFineScavo().size(); i++)
|
||||
loadFiles(c.getPianteFineScavo().get(i), new File(currentFolder, "pianta_" + i), sgClient);
|
||||
}
|
||||
PrintWriter w = new PrintWriter(new File(currentFolder, c.getId() + ".json"));
|
||||
w.append(Serialization.write(c));
|
||||
w.flush();
|
||||
w.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Unable to load {}",c.getId(),e);
|
||||
} catch (StorageHubException e) {
|
||||
log.error("Unable to load {}",c.getId(),e);
|
||||
} catch (Throwable t ){
|
||||
log.error("Unable to load {}", c.getMongo_id(), t);
|
||||
errors.put(c.getMongo_id(),t.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
System.out.println("Imported "+found.size()+" elements into "+dir.getAbsolutePath());
|
||||
System.out.println("Errors count "+errors.size());
|
||||
errors.forEach((s, s2) -> System.out.println("Error for "+s+" : "+s2));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue