task_24166 #11
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -102,7 +104,9 @@
|
|||
|
||||
|
||||
<wb-module deploy-name="geoportal-data-entry-app-3.2.0-SNAPSHOT">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -205,7 +209,9 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -308,7 +314,9 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -411,7 +419,9 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -466,13 +476,21 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<dependent-module archiveName="geoportal-data-viewer-widget-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-viewer-widget/geoportal-data-viewer-widget">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="geoportal-data-mapper-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-mapper/geoportal-data-mapper">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="metadata-profile-form-builder-widget-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-form-builder-widget/metadata-profile-form-builder-widget">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
|
||||
<dependent-module archiveName="geoportal-data-common-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -575,7 +593,9 @@
|
|||
|
||||
|
||||
<property name="context-root" value="geoportal-data-entry-app"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -678,7 +698,9 @@
|
|||
|
||||
|
||||
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -781,7 +803,9 @@
|
|||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ The GeoPortal Data Entry App is an application to build the web forms for data e
|
|||
* pretty-print-json v.1.1. [pretty-print-json](https://github.com/center-key/pretty-print-json) is licensed under [MIT](https://github.com/center-key/pretty-print-json/blob/main/LICENSE.txt)
|
||||
* jsoneditor v.9.5.5. [jsoneditor](https://github.com/josdejong/jsoneditor) is licensed under [Apache License 2.0](https://github.com/josdejong/jsoneditor/blob/master/LICENSE)
|
||||
|
||||
## Architecture
|
||||
|
||||
<img src="https://gcube.wiki.gcube-system.org/gcube/File:GeoPortalDataEntry_Architecture.png" style="max-width:800px;" alt="GeoPortal Data-Entry - Architecture" />
|
||||
|
||||
## Documentation
|
||||
|
||||
N/A
|
||||
|
|
15
pom.xml
15
pom.xml
|
@ -128,12 +128,6 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>openlayer-basic-widgets</artifactId>
|
||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- FWS -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
|
@ -230,6 +224,8 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- TESTS -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -242,6 +238,13 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -89,6 +89,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gwt.user.client.Random;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
|
@ -331,8 +332,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|||
|
||||
String filesetFieldName = filePath.getFieldName();
|
||||
String filesetPath = sectionPath + "." + filesetFieldName;
|
||||
// Replacing $.abc with $..abc
|
||||
filesetPath = filesetPath.replaceFirst("\\.", "..");
|
||||
// // Replacing $.abc with $..abc
|
||||
// filesetPath = filesetPath.replaceFirst("\\.", "..");
|
||||
LOG.info("Going to delete fileset path: {}", filesetPath);
|
||||
try {
|
||||
client.deleteFileset(profileID, projectID, filesetPath, true, true);
|
||||
|
@ -575,7 +576,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|||
FileUploadedRemote remote = (FileUploadedRemote) file;
|
||||
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
||||
InputStream in = new URL(remote.getUrl()).openStream();
|
||||
output = new File(tmpDirPath, remote.getFileName());
|
||||
String fileName = (remote.getFileName()==null || remote.getFileName().isEmpty())?"file_"+Random.nextInt():remote.getFileName();
|
||||
output = new File(tmpDirPath, fileName);
|
||||
Path outputAbsolutePath = Paths.get(output.getAbsolutePath());
|
||||
Files.copy(in, outputAbsolutePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
LOG.info("Remote file: " + remote.getUrl() + ", copied to new file: " + output.getName());
|
||||
|
|
|
@ -0,0 +1,228 @@
|
|||
package org.gcube.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
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.geoportalcommon.geoportal.GeoportalClientCaller;
|
||||
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
|
||||
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gwt.user.client.Random;
|
||||
|
||||
public class Service_Tests {
|
||||
|
||||
private static final String GCUBE_CONFIG_PROPERTIES_FILENAME = "gcube_config.properties";
|
||||
// APP Working Directory + /src/test/resources must be the location of
|
||||
// gcube_config.properties
|
||||
private static String gcube_config_path = String.format("%s/%s",
|
||||
System.getProperty("user.dir") + "/src/test/resources", GCUBE_CONFIG_PROPERTIES_FILENAME);
|
||||
private static String CONTEXT;
|
||||
private static String TOKEN;
|
||||
|
||||
private UseCaseDescriptorCaller clientUCD = null;
|
||||
private ProjectsCaller clientPrj = null;
|
||||
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROJECT_ID = "644a66e944aad51c80409a3b";
|
||||
|
||||
private static String MY_LOGIN = "francesco.mangiacrapa";
|
||||
|
||||
public static final String JSON_$_POINTER = "$";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Service_Tests.class);
|
||||
|
||||
/**
|
||||
* Read context settings.
|
||||
*/
|
||||
public static void readContextSettings() {
|
||||
|
||||
try (InputStream input = new FileInputStream(gcube_config_path)) {
|
||||
|
||||
Properties prop = new Properties();
|
||||
|
||||
// load a properties file
|
||||
prop.load(input);
|
||||
|
||||
CONTEXT = prop.getProperty("CONTEXT");
|
||||
TOKEN = prop.getProperty("TOKEN");
|
||||
// get the property value and print it out
|
||||
System.out.println("CONTEXT: " + CONTEXT);
|
||||
System.out.println("TOKEN: " + TOKEN);
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//@Before
|
||||
public void init() {
|
||||
readContextSettings();
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
clientPrj = GeoportalClientCaller.projects();
|
||||
clientUCD = GeoportalClientCaller.useCaseDescriptors();
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void deleteFileSet_ServiceTest() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
boolean ignore_errors = false;
|
||||
String path = "$.abstractRelazione.filesetIta";
|
||||
|
||||
Project doc = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
|
||||
JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
|
||||
List<String> matchingPaths = wrapper.getMatchingPaths(path);
|
||||
|
||||
LOG.info("matchingPaths is: " + matchingPaths);
|
||||
|
||||
String error = null;
|
||||
if (matchingPaths.isEmpty()) {
|
||||
error = "No Registered FileSet found at " + path;
|
||||
if (!ignore_errors) {
|
||||
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if (matchingPaths.size() > 1 && !ignore_errors) {
|
||||
error = "Multiple Fileset (" + matchingPaths.size() + ") matching " + path;
|
||||
if (!ignore_errors)
|
||||
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (error != null && ignore_errors) {
|
||||
LOG.info("Error detected {}. Ignoring it and returning input doc", error);
|
||||
|
||||
}
|
||||
|
||||
List<Object> listPath = wrapper.getByPath(path);
|
||||
LOG.info("List path: " + listPath);
|
||||
// RegisteredFileSet fs = Serialization.convert(listPath.get(0), RegisteredFileSet.class);
|
||||
// LOG.info("Going to delete {}", fs);
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void registerFileSet() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
Project theProject = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
|
||||
MongoServiceUtil mongoService = new MongoServiceUtil();
|
||||
|
||||
Access access = new Access();
|
||||
access.setLicense("CC-BY");
|
||||
access.setPolicy(AccessPolicy.OPEN);
|
||||
|
||||
String sectionJSONPath = "$.abstractRelazione";
|
||||
String fieldName = "filesetIta";
|
||||
String fieldDefinition = "$.abstractRelazione._children[?(@.filesetIta)]";
|
||||
|
||||
String theFileName = "Application_Profile_for_CSW_2.0-2.pdf";
|
||||
String theFileURL = "https://data.dev.d4science.org/shub/E_bnN2aDJZZUMySy9peE9ScEVLNVFNWjBOZWx0cXQ2UUFkQ2E3Rjc1S29EelJIMEJGbDRoczBnbHVPWHczZTNQTw==";
|
||||
|
||||
FileUploadedRemote file = new FileUploadedRemote();
|
||||
file.setUrl(theFileURL);
|
||||
file.setFileName(theFileName);
|
||||
|
||||
File input = null;
|
||||
File output = null;
|
||||
try {
|
||||
File tempDir = Files.createTempDirectory("GEOPORTAL_REPLACE_FILES_").toFile();
|
||||
String tmpDirPath = tempDir.getAbsolutePath();
|
||||
if (file instanceof FileUploadedRemote) {
|
||||
FileUploadedRemote remote = (FileUploadedRemote) file;
|
||||
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
||||
InputStream in = new URL(remote.getUrl()).openStream();
|
||||
String fileName = (remote.getFileName() == null || remote.getFileName().isEmpty())
|
||||
? "file_" + Random.nextInt()
|
||||
: remote.getFileName();
|
||||
LOG.info("the fileName is: " + fileName);
|
||||
output = new File(tmpDirPath, fileName);
|
||||
Path outputAbsolutePath = Paths.get(output.getAbsolutePath());
|
||||
Files.copy(in, outputAbsolutePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
LOG.info("Remote file: " + remote.getUrl() + ", copied to new file: " + output.getName());
|
||||
} else {
|
||||
LOG.info("Uploaded file is local: " + file.getTempSystemPath());
|
||||
input = new File(file.getTempSystemPath());
|
||||
output = new File(tmpDirPath, file.getFileName());
|
||||
copyContent(input, output);
|
||||
LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName());
|
||||
}
|
||||
tempDir.deleteOnExit();
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
File fileset = output;
|
||||
LOG.info("the fileName is: " + fileset.getName());
|
||||
|
||||
//mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath, fieldName, fieldDefinition, access, fileset);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy content.
|
||||
*
|
||||
* @param a the a
|
||||
* @param b the b
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static void copyContent(File a, File b) throws Exception {
|
||||
FileInputStream in = new FileInputStream(a);
|
||||
FileOutputStream out = new FileOutputStream(b);
|
||||
|
||||
try {
|
||||
|
||||
int n;
|
||||
|
||||
// read() function to read the
|
||||
// byte of data
|
||||
while ((n = in.read()) != -1) {
|
||||
// write() function to write
|
||||
// the byte of data
|
||||
out.write(n);
|
||||
}
|
||||
} finally {
|
||||
if (in != null) {
|
||||
|
||||
// close() function to close the
|
||||
// stream
|
||||
in.close();
|
||||
}
|
||||
// close() function to close
|
||||
// the stream
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
LOG.debug("File Copied");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,34 @@
|
|||
package org.gcube.portlets.user.geoportaldataentry;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
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.document.filesets.RegisteredFileSet;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataServiceModel;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
||||
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
||||
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
||||
|
@ -35,13 +50,16 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView;
|
|||
import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.FileSetDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON.JSONObjectOrdered;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
||||
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge.MERGE_OPTION;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
|
@ -53,6 +71,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gwt.user.client.Random;
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
@ -60,7 +79,7 @@ import com.jayway.jsonpath.spi.json.GsonJsonProvider;
|
|||
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
|
||||
|
||||
public class Complex_Tests {
|
||||
|
||||
|
||||
private static final String GCUBE_CONFIG_PROPERTIES_FILENAME = "gcube_config.properties";
|
||||
// APP Working Directory + /src/test/resources must be the location of
|
||||
// gcube_config.properties
|
||||
|
@ -71,9 +90,9 @@ public class Complex_Tests {
|
|||
|
||||
private UseCaseDescriptorCaller clientUCD = null;
|
||||
private ProjectsCaller clientPrj = null;
|
||||
|
||||
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROJECT_ID = "632c633155e2947b0278c999";
|
||||
private static String PROJECT_ID = "644a66e944aad51c80409a3b";
|
||||
|
||||
private static String MY_LOGIN = "francesco.mangiacrapa";
|
||||
|
||||
|
@ -111,7 +130,7 @@ public class Complex_Tests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read context settings.
|
||||
*/
|
||||
|
@ -143,111 +162,118 @@ public class Complex_Tests {
|
|||
clientPrj = GeoportalClientCaller.projects();
|
||||
clientUCD = GeoportalClientCaller.useCaseDescriptors();
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
// @Test
|
||||
public void testSectionPathInnerParse() throws Exception {
|
||||
String sectionPath = "$.abstractRelazione";
|
||||
|
||||
|
||||
String profileID = "profiledConcessioni";
|
||||
String projectID = "6425598a8593b215a1281e1c";
|
||||
|
||||
|
||||
Configuration configurationGSON = Configuration.builder().jsonProvider(new GsonJsonProvider()).build();
|
||||
|
||||
|
||||
ProjectsCaller client = GeoportalClientCaller.projects();
|
||||
|
||||
|
||||
Project proejct = client.getProjectByID(profileID, projectID);
|
||||
|
||||
|
||||
String jsonSourceProject = proejct.getTheDocument().toJson();
|
||||
|
||||
//If the section path is the Root document, passed as "$.", fixing as "$"
|
||||
if(sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER+".")==0)
|
||||
|
||||
// If the section path is the Root document, passed as "$.", fixing as "$"
|
||||
if (sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0)
|
||||
sectionPath = FormDataObjectToJSON.JSON_$_POINTER;
|
||||
|
||||
|
||||
LOG.info("theString: {}", jsonSourceProject);
|
||||
com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON).read(sectionPath);
|
||||
com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON)
|
||||
.read(sectionPath);
|
||||
LOG.info("currentSectionJObject: {}", currentSectionJObject.toString());
|
||||
LOG.info("sourceSectionObject: {}", currentSectionJObject.toString());
|
||||
|
||||
|
||||
JSONObject targetSectionJObject = new JSONObjectOrdered().instance();
|
||||
targetSectionJObject.put("abstractIta", "Prova REJECT 1");
|
||||
targetSectionJObject.put("titolo", "Prova REJECT abstract relazione di scavo 1");
|
||||
LOG.info("targetSectionJObject: {}", targetSectionJObject.toString());
|
||||
|
||||
String mergedDoc = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(), MERGE_OPTION.REPLACE);
|
||||
String mergedDoc = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(),
|
||||
MERGE_OPTION.REPLACE);
|
||||
LOG.info("output: {}", mergedDoc);
|
||||
|
||||
|
||||
String newDocJson;
|
||||
//Updating path is first level of the root
|
||||
if(sectionPath.equals(FormDataObjectToJSON.JSON_$_POINTER)) {
|
||||
//The merged DOC is the root Document
|
||||
// Updating path is first level of the root
|
||||
if (sectionPath.equals(FormDataObjectToJSON.JSON_$_POINTER)) {
|
||||
// The merged DOC is the root Document
|
||||
newDocJson = mergedDoc;
|
||||
}else {
|
||||
//The merged DOC is a child of the root Document
|
||||
} else {
|
||||
// The merged DOC is a child of the root Document
|
||||
Gson gson = new Gson();
|
||||
JsonObject gsonOject = gson.fromJson(mergedDoc, JsonObject.class);
|
||||
// Putting the merged section into Document
|
||||
DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, gsonOject);
|
||||
newDocJson = newContextDocJson.json().toString();
|
||||
|
||||
DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath,
|
||||
gsonOject);
|
||||
newDocJson = newContextDocJson.json().toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class);
|
||||
LOG.info("New document is: {}", updatedDocument.toJson());
|
||||
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
// @Test
|
||||
public void testSectionPathRootParse() throws Exception {
|
||||
String sectionPath = "$.";
|
||||
|
||||
|
||||
String profileID = "profiledConcessioni";
|
||||
String projectID = "6425598a8593b215a1281e1c";
|
||||
|
||||
|
||||
Configuration configurationGSON = Configuration.builder().jsonProvider(new GsonJsonProvider()).build();
|
||||
|
||||
|
||||
ProjectsCaller client = GeoportalClientCaller.projects();
|
||||
|
||||
|
||||
Project proejct = client.getProjectByID(profileID, projectID);
|
||||
|
||||
|
||||
String jsonSourceProject = proejct.getTheDocument().toJson();
|
||||
|
||||
//If the section path is the Root document, passed as "$.", fixing as "$"
|
||||
if(sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER+".")==0)
|
||||
|
||||
// If the section path is the Root document, passed as "$.", fixing as "$"
|
||||
if (sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0)
|
||||
sectionPath = FormDataObjectToJSON.JSON_$_POINTER;
|
||||
|
||||
|
||||
LOG.info("theString: {}", jsonSourceProject);
|
||||
com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON).read(sectionPath);
|
||||
com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON)
|
||||
.read(sectionPath);
|
||||
LOG.info("currentSectionJObject: {}", currentSectionJObject.toString());
|
||||
LOG.info("sourceSectionObject: {}", currentSectionJObject.toString());
|
||||
|
||||
|
||||
JSONObject targetSectionJObject = new JSONObjectOrdered().instance();
|
||||
targetSectionJObject.put("nome", proejct.getTheDocument().get("nome")+" 1");
|
||||
targetSectionJObject.put("titolo", proejct.getTheDocument().get("introduzione")+ " 1");
|
||||
targetSectionJObject.put("nome", proejct.getTheDocument().get("nome") + " 1");
|
||||
targetSectionJObject.put("titolo", proejct.getTheDocument().get("introduzione") + " 1");
|
||||
LOG.info("targetSectionJObject: {}", targetSectionJObject.toString());
|
||||
|
||||
|
||||
// JSONObject mergedSection = FormDataObjectToJSON.deepMerge(sourceSectionObject,
|
||||
// targetSectionJObject);
|
||||
|
||||
String output = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(), MERGE_OPTION.REPLACE);
|
||||
|
||||
String output = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(),
|
||||
MERGE_OPTION.REPLACE);
|
||||
LOG.info("output: {}", output);
|
||||
|
||||
|
||||
Gson gson = new Gson();
|
||||
JsonObject gsonOject = gson.fromJson(output, JsonObject.class);
|
||||
|
||||
// Putting the merged section into Document
|
||||
DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, gsonOject);
|
||||
//DocumentContext newDocument = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, new JSONObject(output));
|
||||
//String newDocJson = JsonPath.parse(jsonSourceProject).set(sectionPath, new JSONObject(output)).jsonString();
|
||||
String newDocJson = newContextDocJson.json().toString();
|
||||
DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath,
|
||||
gsonOject);
|
||||
// DocumentContext newDocument = JsonPath.parse(jsonSourceProject,
|
||||
// configurationGSON).set(sectionPath, new JSONObject(output));
|
||||
// String newDocJson = JsonPath.parse(jsonSourceProject).set(sectionPath, new
|
||||
// JSONObject(output)).jsonString();
|
||||
String newDocJson = newContextDocJson.json().toString();
|
||||
LOG.info("Going to call updateProject with document: {}", newDocJson);
|
||||
|
||||
Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class);
|
||||
LOG.info("New document is: {}", updatedDocument.toJson());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//@Before
|
||||
}
|
||||
|
||||
// @Before
|
||||
public void preloadgCubeProfilesForUCDs() {
|
||||
LOG.debug("preloadgCubeProfilesForUCDs called");
|
||||
try {
|
||||
|
@ -309,6 +335,145 @@ public class Complex_Tests {
|
|||
}
|
||||
|
||||
//@Test
|
||||
public void deleteFileSet_ServiceTest() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
boolean ignore_errors = false;
|
||||
String path = "$.abstractRelazione.filesetIta";
|
||||
|
||||
Project doc = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
|
||||
JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
|
||||
List<String> matchingPaths = wrapper.getMatchingPaths(path);
|
||||
|
||||
LOG.info("matchingPaths is: " + matchingPaths);
|
||||
|
||||
String error = null;
|
||||
if (matchingPaths.isEmpty()) {
|
||||
error = "No Registered FileSet found at " + path;
|
||||
if (!ignore_errors) {
|
||||
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if (matchingPaths.size() > 1 && !ignore_errors) {
|
||||
error = "Multiple Fileset (" + matchingPaths.size() + ") matching " + path;
|
||||
if (!ignore_errors)
|
||||
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (error != null && ignore_errors) {
|
||||
LOG.info("Error detected {}. Ignoring it and returning input doc", error);
|
||||
|
||||
}
|
||||
|
||||
List<Object> listPath = wrapper.getByPath(path);
|
||||
LOG.info("List path: "+listPath);
|
||||
// RegisteredFileSet fs = Serialization.convert(listPath.get(0), RegisteredFileSet.class);
|
||||
// LOG.info("Going to delete {}", fs);
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void registerFileSet() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
Project theProject = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
|
||||
MongoServiceUtil mongoService = new MongoServiceUtil();
|
||||
|
||||
Access access = new Access();
|
||||
access.setLicense("CC-BY");
|
||||
access.setPolicy(AccessPolicy.OPEN);
|
||||
|
||||
String sectionJSONPath = "$.abstractRelazione";
|
||||
String fieldName = "filesetIta";
|
||||
String fieldDefinition = "$.abstractRelazione._children[?(@.filesetIta)]";
|
||||
|
||||
String theFileName = "Application_Profile_for_CSW_2.0-2.pdf";
|
||||
String theFileURL = "https://data.dev.d4science.org/shub/E_bnN2aDJZZUMySy9peE9ScEVLNVFNWjBOZWx0cXQ2UUFkQ2E3Rjc1S29EelJIMEJGbDRoczBnbHVPWHczZTNQTw==";
|
||||
|
||||
FileUploadedRemote file = new FileUploadedRemote();
|
||||
file.setUrl(theFileURL);
|
||||
file.setFileName(theFileName);
|
||||
|
||||
File input = null;
|
||||
File output = null;
|
||||
try {
|
||||
File tempDir = Files.createTempDirectory("GEOPORTAL_REPLACE_FILES_").toFile();
|
||||
String tmpDirPath = tempDir.getAbsolutePath();
|
||||
if (file instanceof FileUploadedRemote) {
|
||||
FileUploadedRemote remote = (FileUploadedRemote) file;
|
||||
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
||||
InputStream in = new URL(remote.getUrl()).openStream();
|
||||
String fileName = (remote.getFileName() == null || remote.getFileName().isEmpty())
|
||||
? "file_" + Random.nextInt()
|
||||
: remote.getFileName();
|
||||
LOG.info("the fileName is: " + fileName);
|
||||
output = new File(tmpDirPath, fileName);
|
||||
Path outputAbsolutePath = Paths.get(output.getAbsolutePath());
|
||||
Files.copy(in, outputAbsolutePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
LOG.info("Remote file: " + remote.getUrl() + ", copied to new file: " + output.getName());
|
||||
} else {
|
||||
LOG.info("Uploaded file is local: " + file.getTempSystemPath());
|
||||
input = new File(file.getTempSystemPath());
|
||||
output = new File(tmpDirPath, file.getFileName());
|
||||
copyContent(input, output);
|
||||
LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName());
|
||||
}
|
||||
// tempDir.deleteOnExit();
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
File fileset = output;
|
||||
LOG.info("the fileName is: " + fileset.getName());
|
||||
|
||||
mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath, fieldName, fieldDefinition,
|
||||
access, fileset);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy content.
|
||||
*
|
||||
* @param a the a
|
||||
* @param b the b
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static void copyContent(File a, File b) throws Exception {
|
||||
FileInputStream in = new FileInputStream(a);
|
||||
FileOutputStream out = new FileOutputStream(b);
|
||||
|
||||
try {
|
||||
|
||||
int n;
|
||||
|
||||
// read() function to read the
|
||||
// byte of data
|
||||
while ((n = in.read()) != -1) {
|
||||
// write() function to write
|
||||
// the byte of data
|
||||
out.write(n);
|
||||
}
|
||||
} finally {
|
||||
if (in != null) {
|
||||
|
||||
// close() function to close the
|
||||
// stream
|
||||
in.close();
|
||||
}
|
||||
// close() function to close
|
||||
// the stream
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
LOG.debug("File Copied");
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testReadProjectForUCDDataEntry() {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
|
Loading…
Reference in New Issue