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 com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.cms.tests.TestDocuments;
|
||||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.document.Project;
|
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 {
|
public void createNew () throws RemoteException, FileNotFoundException, JsonProcessingException {
|
||||||
String profileID=getUCID();
|
String profileID=getUCID();
|
||||||
|
|
||||||
String myJSON=null;
|
Document myDocument= new Document();
|
||||||
Document myDocument = Document.parse(myJSON);
|
myDocument.put("section",new Document("title","myTitle"));
|
||||||
|
|
||||||
Projects<Project> client = getClient(profileID);
|
Projects<Project> client = getClient(profileID);
|
||||||
|
|
||||||
|
@ -46,9 +47,9 @@ public abstract class GenericUseCases extends BasicVreTests{
|
||||||
Project project = client.createNew(myDocument);
|
Project project = client.createNew(myDocument);
|
||||||
|
|
||||||
|
|
||||||
String parentPath = "";
|
String parentPath = "$.section";
|
||||||
String fieldName = "";
|
String fieldName = "fileset";
|
||||||
String fieldDefinition = "";
|
String fieldDefinition = "$.section._children[?(@.fileset)]";
|
||||||
|
|
||||||
// Prepare request
|
// Prepare request
|
||||||
RegisterFileSetRequest fsRequest = FileSets.
|
RegisterFileSetRequest fsRequest = FileSets.
|
||||||
|
|
|
@ -64,7 +64,11 @@ public class FileSets {
|
||||||
return this;
|
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;
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.statefulMongoConcessioni;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ExportConcessioniAsProfiledDocuments {
|
public class ExportConcessioniAsProjects {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class ExportConcessioniAsProfiledDocuments {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// read from imported folder
|
// 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";
|
String targetContext="/gcube/devsec/devVRE";
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.gcube.application.cms.usecases;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
import org.gcube.application.geoportal.client.legacy.ConcessioniManager;
|
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.client.utils.Serialization;
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.legacy.*;
|
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.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.statefulMongoConcessioni;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +38,8 @@ public class Import {
|
||||||
// String sourceContext="/pred4s/preprod/preVRE";
|
// String sourceContext="/pred4s/preprod/preVRE";
|
||||||
|
|
||||||
|
|
||||||
|
Boolean saveFilesLocally=false;
|
||||||
|
|
||||||
|
|
||||||
// GET FOM SOURCE
|
// GET FOM SOURCE
|
||||||
TokenSetter.set(sourceContext);
|
TokenSetter.set(sourceContext);
|
||||||
|
@ -38,16 +47,21 @@ public class Import {
|
||||||
StorageHubClient sgClient=new StorageHubClient();
|
StorageHubClient sgClient=new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
// ConcessioniManagerI manager= statefulMongoConcessioni().build();
|
ConcessioniManagerI sourceManager= statefulMongoConcessioni().build();
|
||||||
|
|
||||||
ConcessioniManager sourceManager = new ConcessioniManager();
|
|
||||||
ArrayList<Concessione> found=new ArrayList<>();
|
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 {
|
try {
|
||||||
File currentFolder=new File (dir.toString(),c.getId()+"");
|
File currentFolder = new File(dir.toString(), c.getMongo_id() + "");
|
||||||
currentFolder.mkdirs();
|
currentFolder.mkdirs();
|
||||||
|
|
||||||
//Load locally
|
//Load locally
|
||||||
|
if(saveFilesLocally) {
|
||||||
// POSIZIONAMENTO
|
// POSIZIONAMENTO
|
||||||
loadFiles(c.getPosizionamentoScavo(), new File(currentFolder, "pos"), sgClient);
|
loadFiles(c.getPosizionamentoScavo(), new File(currentFolder, "pos"), sgClient);
|
||||||
// RELAZIONE
|
// RELAZIONE
|
||||||
|
@ -59,24 +73,22 @@ public class Import {
|
||||||
// Piante
|
// Piante
|
||||||
for (int i = 0; i < c.getPianteFineScavo().size(); i++)
|
for (int i = 0; i < c.getPianteFineScavo().size(); i++)
|
||||||
loadFiles(c.getPianteFineScavo().get(i), new File(currentFolder, "pianta_" + i), sgClient);
|
loadFiles(c.getPianteFineScavo().get(i), new File(currentFolder, "pianta_" + i), sgClient);
|
||||||
|
}
|
||||||
found.add(c);
|
|
||||||
|
|
||||||
|
|
||||||
PrintWriter w = new PrintWriter(new File(currentFolder, c.getId() + ".json"));
|
PrintWriter w = new PrintWriter(new File(currentFolder, c.getId() + ".json"));
|
||||||
w.append(Serialization.write(c));
|
w.append(Serialization.write(c));
|
||||||
w.flush();
|
w.flush();
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (Throwable t ){
|
||||||
log.error("Unable to load {}",c.getId(),e);
|
log.error("Unable to load {}", c.getMongo_id(), t);
|
||||||
} catch (StorageHubException e) {
|
errors.put(c.getMongo_id(),t.getMessage());
|
||||||
log.error("Unable to load {}",c.getId(),e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
System.out.println("Imported "+found.size()+" elements into "+dir.getAbsolutePath());
|
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