2022-03-01 12:19:37 +01:00
|
|
|
package org.gcube.application.geoportalcommon;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2022-03-04 14:39:44 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2022-03-01 12:19:37 +01:00
|
|
|
|
|
|
|
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig;
|
2022-03-04 14:39:44 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
2022-03-01 12:19:37 +01:00
|
|
|
|
|
|
|
public class MockDocumentConfigurationReader {
|
2022-03-04 14:39:44 +01:00
|
|
|
|
|
|
|
private List<DocumentConfigDV> listDocumentConfigsDV = new ArrayList<DocumentConfigDV>();
|
|
|
|
|
2022-03-01 12:19:37 +01:00
|
|
|
public MockDocumentConfigurationReader() {
|
|
|
|
try {
|
|
|
|
loadDocumentConfiguration();
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 14:39:44 +01:00
|
|
|
|
|
|
|
//THIS IS A MOCK
|
|
|
|
private void loadDocumentConfiguration() throws Exception {
|
2022-03-01 12:19:37 +01:00
|
|
|
System.out.println("loadDocumentConfiguration called");
|
|
|
|
String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json";
|
2022-03-04 14:39:44 +01:00
|
|
|
|
|
|
|
DocumentConfigDV dc = getDocumentConfigVO(filePath);
|
|
|
|
listDocumentConfigsDV.add(dc);
|
|
|
|
|
|
|
|
filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config2.json";
|
|
|
|
dc = getDocumentConfigVO(filePath);
|
|
|
|
listDocumentConfigsDV.add(dc);
|
|
|
|
|
|
|
|
filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config3.json";
|
|
|
|
dc = getDocumentConfigVO(filePath);
|
|
|
|
listDocumentConfigsDV.add(dc);
|
2022-03-07 11:52:43 +01:00
|
|
|
|
|
|
|
filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config4.json";
|
|
|
|
dc = getDocumentConfigVO(filePath);
|
|
|
|
listDocumentConfigsDV.add(dc);
|
2022-03-04 14:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private DocumentConfigDV getDocumentConfigVO(String filePath) throws JsonProcessingException, IOException {
|
2022-03-01 12:19:37 +01:00
|
|
|
String theFile = readFile(filePath);
|
2022-03-04 14:39:44 +01:00
|
|
|
System.out.println("the file is: " + theFile);
|
2022-03-01 12:19:37 +01:00
|
|
|
DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile,
|
|
|
|
DocumentConfig.class);
|
|
|
|
System.out.println(dc);
|
2022-03-04 14:39:44 +01:00
|
|
|
|
|
|
|
return ConvertToDataValueObjectModel.toDocumentConfigDV(dc);
|
2022-03-01 12:19:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static String readFile(String filePath) {
|
|
|
|
String content = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
content = new String(Files.readAllBytes(Paths.get(filePath)));
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2022-03-04 14:39:44 +01:00
|
|
|
public List<DocumentConfigDV> getListDocumentConfig() {
|
|
|
|
return listDocumentConfigsDV;
|
2022-03-01 12:19:37 +01:00
|
|
|
}
|
|
|
|
}
|