This commit is contained in:
Francesco Mangiacrapa 2023-02-03 11:42:06 +01:00
parent 5474b5e25b
commit 6f77cf23e9
5 changed files with 76 additions and 27 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry including="**/*.java" kind="src" output="target/geoportal-data-entry-app-3.0.1/WEB-INF/classes" path="src/main/java"> <classpathentry including="**/*.java" kind="src" output="target/geoportal-data-entry-app-3.0.2-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/geoportal-data-entry-app-3.0.1/WEB-INF/classes"/> <classpathentry kind="output" path="target/geoportal-data-entry-app-3.0.2-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
jarsExcludedFromWebInfLib= jarsExcludedFromWebInfLib=
lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-3.0.1 lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-3.0.2-SNAPSHOT
warSrcDir=src/main/webapp warSrcDir=src/main/webapp
warSrcDirIsOutput=false warSrcDirIsOutput=false

View File

@ -79,7 +79,7 @@
<wb-module deploy-name="geoportal-data-entry-app-3.0.1"> <wb-module deploy-name="geoportal-data-entry-app-3.0.2-SNAPSHOT">
@ -356,9 +356,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<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.0.2-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common"> <dependent-module archiveName="geoportal-data-common-2.0.2-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>

View File

@ -21,11 +21,14 @@ import org.apache.commons.io.FileUtils;
import org.bson.Document; import org.bson.Document;
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;
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.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
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.RelationshipDefinition; import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportalcommon.ConvertToDataServiceModel;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.ProjectDVBuilder; import org.gcube.application.geoportalcommon.ProjectDVBuilder;
@ -76,6 +79,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
/** /**
* The server side implementation of the RPC service. * The server side implementation of the RPC service.
@ -238,6 +243,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
sectionJSONPathIndexer = new HashMap<String, Integer>(); sectionJSONPathIndexer = new HashMap<String, Integer>();
} }
String theJSONDocument = theProject.getTheDocument().toJson();
for (Tree_Node<GeoNaFormDataObject> treeNodeChild_GNA_DO : tree_Node.getChildren()) { for (Tree_Node<GeoNaFormDataObject> treeNodeChild_GNA_DO : tree_Node.getChildren()) {
LOG.debug("Going to upload the files of tree node: " + treeNodeChild_GNA_DO); LOG.debug("Going to upload the files of tree node: " + treeNodeChild_GNA_DO);
@ -330,20 +337,23 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
File[] fileset = uploadedFileset.getFileset(); File[] fileset = uploadedFileset.getFileset();
FilePathDV filePath = uploadedFileset.getFilePathDV(); FilePathDV filePath = uploadedFileset.getFilePathDV();
Access access;
// If the maxOccurs is not 1 // If the maxOccurs is not 1
if (profile.getMaxOccurs() == 0 || profile.getMaxOccurs() > 1) { if (profile.getMaxOccurs() == 0 || profile.getMaxOccurs() > 1) {
LOG.info("The gCube Profile with the section " + sectionJSONPath LOG.info("The gCube Profile with the section " + sectionJSONPath
+ " has maxOccurs > 1 need to manage it as array, going to add the array index"); + " has maxOccurs > 1 need to manage it as array, going to add the array index");
String arraySectionJSONPAth = String.format("%s[%d]", sectionJSONPath, jpcV); String arraySectionJSONPAth = String.format("%s[%d]", sectionJSONPath, jpcV);
LOG.debug("registering the fileset in the array section: " + sectionJSONPath); LOG.debug("registering the fileset in the array section: " + sectionJSONPath);
access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,arraySectionJSONPAth);
mongoService.registerFileSet(profileID, theProject, arraySectionJSONPAth, mongoService.registerFileSet(profileID, theProject, arraySectionJSONPAth,
filePath.getFieldName(), filePath.getFieldDefinition(), fileset); filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
} else { } else {
LOG.info("The gCube Profile with the section " + sectionJSONPath + " has maxOccurs = 1"); LOG.info("The gCube Profile with the section " + sectionJSONPath + " has maxOccurs = 1");
LOG.debug("registering the fileset in the section: " + sectionJSONPath); LOG.debug("registering the fileset in the section: " + sectionJSONPath);
access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,sectionJSONPath);
mongoService.registerFileSet(profileID, theProject, sectionJSONPath, filePath.getFieldName(), mongoService.registerFileSet(profileID, theProject, sectionJSONPath, filePath.getFieldName(),
filePath.getFieldDefinition(), fileset); filePath.getFieldDefinition(), access, fileset);
} }
} }
@ -358,6 +368,46 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
} }
public Access getAccessFromDocumentSection(String theJSONDocument, String sectionJSONPath) {
String accessPolicyPath = String.format("%s.%s", sectionJSONPath, ConvertToDataValueObjectModel.POLICY);
AccessPolicy accessPolicy = AccessPolicy.OPEN;
com.jayway.jsonpath.Configuration config = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
// Reading policy fields
try {
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
String policy = theSectionPolycJsonPath.read(theJSONDocument, config).toString();
LOG.debug("Read " + ConvertToDataValueObjectModel.POLICY + ": " + policy + ", from section: "
+ accessPolicyPath);
if (policy != null) {
accessPolicy = AccessPolicy.valueOf(policy.toUpperCase());
}
} catch (Exception e) {
LOG.info("No " + ConvertToDataValueObjectModel.POLICY + "found in the path: " + accessPolicyPath);
}
// Reading policy fields
String licenseIDPath = String.format("%s.%s", sectionJSONPath, ConvertToDataValueObjectModel.LICENSE_ID);
String licenseID = null;
try {
JsonPath theSectionLicenseJsonPath = JsonPath.compile(licenseIDPath);
licenseID = theSectionLicenseJsonPath.read(theJSONDocument, config).toString();
LOG.debug("Read " + ConvertToDataValueObjectModel.LICENSE_ID + ": " + licenseID + ", from section: "
+ theSectionLicenseJsonPath);
} catch (Exception e) {
LOG.info("No " + ConvertToDataValueObjectModel.LICENSE_ID + "found in the path: " + licenseIDPath);
}
Access access = new Access();
access.setPolicy(accessPolicy);
if (licenseID != null)
access.setLicense(licenseID);
LOG.info("Access is: " + access);
return access;
}
/** /**
* Creates the temp file on storage. * Creates the temp file on storage.
* *
@ -521,26 +571,26 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
searchedData.setTotalItems(totalProjectForProfile); searchedData.setTotalItems(totalProjectForProfile);
LOG.info("Total Docs read from config: " + totalProjectForProfile); LOG.info("Total Docs read from config: " + totalProjectForProfile);
// Saving client PROJECTION // Saving client PROJECTION
LinkedHashMap<String, Object> originalProjection = filter.getProjection(); LinkedHashMap<String, Object> originalProjection = filter.getProjection();
int totalItems = totalProjectForProfile; int totalItems = totalProjectForProfile;
//PERFORMING FIRST QUERY FOR IDS IF AND ONLY IF WHERE CONDITIONS IN THE QUERY. // PERFORMING FIRST QUERY FOR IDS IF AND ONLY IF WHERE CONDITIONS IN THE QUERY.
//SEARCHING FACILITY IS ENACTING. // SEARCHING FACILITY IS ENACTING.
if(filter.getConditions()!=null) { if (filter.getConditions() != null) {
// Setting PROJECTION ONLY FOR PROEJCT ID // Setting PROJECTION ONLY FOR PROEJCT ID
LinkedHashMap<String, Object> projectionForIDs = new LinkedHashMap<String, Object>(); LinkedHashMap<String, Object> projectionForIDs = new LinkedHashMap<String, Object>();
projectionForIDs.put(Project.ID, 1); projectionForIDs.put(Project.ID, 1);
filter.setProjection(projectionForIDs); filter.setProjection(projectionForIDs);
// FIRST QUERY TO RETRIEVE IDs // FIRST QUERY TO RETRIEVE IDs
// LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS // LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS
//Calculating always the size starting from 0 // Calculating always the size starting from 0
final Iterator<Project> projectsIDs = client.queryOnMongo(theProfileID, totalProjectForProfile, 0, null, final Iterator<Project> projectsIDs = client.queryOnMongo(theProfileID, totalProjectForProfile, 0, null,
filter); filter);
//Getting the Project IDs from the Iterable // Getting the Project IDs from the Iterable
Iterable<Project> itP = () -> projectsIDs; Iterable<Project> itP = () -> projectsIDs;
Stream<Project> targetStream = StreamSupport.stream(itP.spliterator(), false); Stream<Project> targetStream = StreamSupport.stream(itP.spliterator(), false);
List<String> listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList()); List<String> listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList());
@ -548,13 +598,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
searchedData.setTotalItems(totalItems); searchedData.setTotalItems(totalItems);
LOG.info("Total Docs read from query per ID: " + totalItems); LOG.info("Total Docs read from query per ID: " + totalItems);
} }
//NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT // NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT
// SETTING ORIGINAL PROJECTION FROM CLIENT // SETTING ORIGINAL PROJECTION FROM CLIENT
filter.setProjection(originalProjection); filter.setProjection(originalProjection);
// LIMIT IS FROM CLIENT // LIMIT IS FROM CLIENT
Iterator<Project> projects = client.queryOnMongo(theProfileID, totalItems, start, limit, Iterator<Project> projects = client.queryOnMongo(theProfileID, totalItems, start, limit, filter);
filter);
searchedData.setClientStartIndex(start); searchedData.setClientStartIndex(start);
searchedData.setLimit(limit); searchedData.setLimit(limit);
@ -562,9 +611,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
List<ResultDocumentDV> toReturnList = ConvertToDataValueObjectModel.toListResultDocument(projects); List<ResultDocumentDV> toReturnList = ConvertToDataValueObjectModel.toListResultDocument(projects);
searchedData.setData(toReturnList); searchedData.setData(toReturnList);
LOG.info("Total Docs page size returned:" + toReturnList.size() + ", start: " + start + ", limit: " + limit); LOG.info(
"Total Docs page size returned:" + toReturnList.size() + ", start: " + start + ", limit: " + limit);
if (totalProjectForProfile == limit || totalProjectForProfile == 0) { if (totalProjectForProfile == limit || totalProjectForProfile == 0) {
LOG.debug("Page completed returning " + totalProjectForProfile + " projects"); LOG.debug("Page completed returning " + totalProjectForProfile + " projects");
int newOffset = start + limit; int newOffset = start + limit;

View File

@ -15,6 +15,7 @@ import org.bson.Document;
import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.faults.InvalidRequestException;
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.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile; import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.MongoConcessioni;
@ -63,7 +64,7 @@ public class MongoServiceUtil {
} }
public void registerFileSet(String profileID, Project project, String parentPath, String fieldName, public void registerFileSet(String profileID, Project project, String parentPath, String fieldName,
String fieldDefinition, File... files) String fieldDefinition, Access access, File... files)
throws RemoteException, FileNotFoundException, JsonProcessingException, InvalidRequestException { throws RemoteException, FileNotFoundException, JsonProcessingException, InvalidRequestException {
LOG.debug("registerFileSet called for profileID: " + profileID); LOG.debug("registerFileSet called for profileID: " + profileID);
@ -71,6 +72,7 @@ public class MongoServiceUtil {
// Prepare request // Prepare request
RegisterFileSetRequest fsRequest = FileSets.prepareRequest(new StorageUtils(), parentPath, fieldName, RegisterFileSetRequest fsRequest = FileSets.prepareRequest(new StorageUtils(), parentPath, fieldName,
fieldDefinition, files); fieldDefinition, files);
fsRequest.setToSetAccess(access);
project = client.registerFileSet(project.getId(), fsRequest); project = client.registerFileSet(project.getId(), fsRequest);
LOG.trace("Resulting Project : " + project); LOG.trace("Resulting Project : " + project);