2020-10-07 17:04:13 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
|
|
|
|
2022-06-29 11:48:09 +02:00
|
|
|
import java.io.File;
|
2022-10-19 11:42:37 +02:00
|
|
|
import java.io.FileInputStream;
|
2022-10-20 16:58:29 +02:00
|
|
|
import java.io.FileNotFoundException;
|
2022-10-19 11:42:37 +02:00
|
|
|
import java.io.FileOutputStream;
|
2022-10-20 16:58:29 +02:00
|
|
|
import java.io.InputStream;
|
2023-04-17 16:03:40 +02:00
|
|
|
import java.net.URL;
|
2022-10-20 16:58:29 +02:00
|
|
|
import java.nio.file.Files;
|
2023-04-17 16:03:40 +02:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.nio.file.StandardCopyOption;
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.util.ArrayList;
|
2022-03-07 17:48:32 +01:00
|
|
|
import java.util.Arrays;
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.util.HashMap;
|
2022-08-11 12:07:07 +02:00
|
|
|
import java.util.Iterator;
|
2022-11-30 09:45:36 +01:00
|
|
|
import java.util.LinkedHashMap;
|
2020-10-20 09:58:56 +02:00
|
|
|
import java.util.List;
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.util.Map;
|
2022-11-30 09:45:36 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.StreamSupport;
|
2020-10-20 09:58:56 +02:00
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2022-09-14 10:12:07 +02:00
|
|
|
import org.bson.Document;
|
|
|
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2023-02-09 15:53:44 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.access.Access;
|
2022-06-29 11:48:09 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
2022-10-20 16:58:29 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.TempFile;
|
2022-10-03 17:52:16 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
2022-10-20 16:58:29 +02:00
|
|
|
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
2023-02-09 15:53:44 +01:00
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataServiceModel;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
2020-12-01 18:15:13 +01:00
|
|
|
import org.gcube.application.geoportalcommon.GeoportalCommon;
|
2022-09-13 16:18:40 +02:00
|
|
|
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
|
|
|
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
|
|
|
|
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
2021-12-21 16:51:56 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
|
2022-10-18 16:38:48 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
|
2021-12-06 17:24:27 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
2022-09-13 13:52:44 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.config.OPERATION_ON_ITEM;
|
2021-12-06 17:24:27 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
|
2021-12-21 16:51:56 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
|
2022-08-11 12:07:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
2022-09-13 16:18:40 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
2022-05-20 12:31:58 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
2022-08-11 12:07:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV;
|
2022-09-13 16:18:40 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
2022-11-17 11:53:11 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV;
|
2022-08-11 12:07:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
|
2022-10-03 17:52:16 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV;
|
2022-08-11 12:07:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV;
|
2023-04-27 16:39:21 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView;
|
2022-12-07 09:43:48 +01:00
|
|
|
import org.gcube.application.geoportaldatamapper.Geoportal_JSON_Mapper;
|
|
|
|
import org.gcube.application.geoportaldatamapper.shared.ProjectEdit;
|
2021-11-26 16:05:05 +01:00
|
|
|
import org.gcube.common.portal.PortalContext;
|
2022-10-20 16:58:29 +02:00
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
2020-10-22 16:50:14 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
|
2022-03-04 16:44:51 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard;
|
2023-04-20 16:34:52 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
2023-04-21 15:27:29 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge.MERGE_OPTION;
|
2020-10-21 16:52:07 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
2022-09-26 16:17:41 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile;
|
2020-10-20 09:58:56 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
2022-09-26 16:17:41 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoportalISConfig;
|
2022-07-08 16:38:45 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
2021-11-26 16:05:05 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
|
2020-10-20 11:49:23 +02:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
|
2023-04-17 16:03:40 +02:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote;
|
2021-11-26 16:05:05 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
2020-10-20 11:49:23 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
2022-03-07 17:48:32 +01:00
|
|
|
import org.json.JSONObject;
|
2020-10-20 11:49:23 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2020-10-07 17:04:13 +02:00
|
|
|
|
2023-04-20 16:34:52 +02:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.JsonObject;
|
2023-05-02 11:34:53 +02:00
|
|
|
import com.google.gwt.user.client.Random;
|
2020-10-07 17:04:13 +02:00
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
2023-04-17 16:03:40 +02:00
|
|
|
import com.jayway.jsonpath.Configuration;
|
2023-04-20 16:34:52 +02:00
|
|
|
import com.jayway.jsonpath.DocumentContext;
|
2023-04-17 16:03:40 +02:00
|
|
|
import com.jayway.jsonpath.JsonPath;
|
|
|
|
import com.jayway.jsonpath.spi.json.GsonJsonProvider;
|
2020-10-07 17:04:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
2020-12-01 18:15:13 +01:00
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
|
|
|
* Dec 1, 2020
|
2020-10-07 17:04:13 +02:00
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2020-10-22 16:50:14 +02:00
|
|
|
public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implements GeoportalDataEntryService {
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2020-10-21 15:36:50 +02:00
|
|
|
public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE";
|
2020-10-22 16:50:14 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class);
|
2020-10-20 11:49:23 +02:00
|
|
|
|
2021-12-21 16:51:56 +01:00
|
|
|
/**
|
|
|
|
* Gets the GNA data entry config profile.
|
|
|
|
*
|
|
|
|
* @return the GNA data entry config profile
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
private GNADataEntryConfigProfile getGNADataEntryConfigProfile() throws Exception {
|
|
|
|
|
|
|
|
GNADataEntryConfigProfile profile = SessionUtil.getGNADataEntryConfigProfile(getThreadLocalRequest());
|
|
|
|
if (profile == null) {
|
|
|
|
LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " is null, loading configurations from IS");
|
2022-03-17 18:08:58 +01:00
|
|
|
// to be sure
|
2021-12-21 16:51:56 +01:00
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
GeoportalCommon gCommon = new GeoportalCommon();
|
|
|
|
profile = gCommon.readGNADataEntryConfig();
|
|
|
|
SessionUtil.setGNADataEntryConfigProfile(getThreadLocalRequest(), profile);
|
|
|
|
} else {
|
|
|
|
LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " read from session");
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2020-12-01 18:15:13 +01:00
|
|
|
/**
|
|
|
|
* Save geona data forms.
|
|
|
|
*
|
2022-11-17 11:53:11 +01:00
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param tree_Node the tree node
|
|
|
|
* @param stepsOnPostCreation the steps on post creation
|
2020-12-01 18:15:13 +01:00
|
|
|
* @return the commit report
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-10-20 11:49:23 +02:00
|
|
|
@Override
|
2022-10-06 11:25:31 +02:00
|
|
|
public CommitReport saveGeonaDataForms(String profileID, Tree_Node<GeoNaFormDataObject> tree_Node,
|
|
|
|
List<String> stepsOnPostCreation) throws Exception {
|
2022-05-20 12:31:58 +02:00
|
|
|
LOG.info("saveGeonaDataForms called for profileID {}", profileID);
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
MongoServiceUtil mongoService = new MongoServiceUtil();
|
2022-05-20 12:31:58 +02:00
|
|
|
String theDocumentString = null;
|
2020-10-21 16:16:53 +02:00
|
|
|
try {
|
2022-03-17 18:08:58 +01:00
|
|
|
|
|
|
|
FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON();
|
2022-08-02 17:06:50 +02:00
|
|
|
JSONObject theDocument = metadataConverter.convert(tree_Node, null);
|
2022-05-20 12:31:58 +02:00
|
|
|
theDocumentString = theDocument.toString();
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.info("Got Document: " + theDocumentString);
|
2022-05-20 12:31:58 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on converting form data: ", e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on converting data, try again or contact the support. Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
Project theProject = null;
|
|
|
|
try {
|
2022-03-17 18:08:58 +01:00
|
|
|
|
2021-07-23 17:40:50 +02:00
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.debug("Going to create the project...");
|
2022-05-20 12:31:58 +02:00
|
|
|
theProject = mongoService.createNew(profileID, theDocumentString);
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.info("Project created with id: " + theProject.getId() + " and profileID: " + theProject.getProfileID());
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2022-05-20 12:31:58 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on creating the project: ", e);
|
|
|
|
throw new Exception("Error occurred on creating new project, try again or contact the support. Error: "
|
|
|
|
+ e.getMessage());
|
|
|
|
}
|
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
List<File> listTempDirs = new ArrayList<File>();
|
|
|
|
|
2022-05-20 12:31:58 +02:00
|
|
|
try {
|
2022-08-03 17:50:47 +02:00
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
// Uploading files into tempDirs in order to avoid clashing of names
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.debug("Going to upload the files");
|
2022-10-20 16:58:29 +02:00
|
|
|
listTempDirs = recursiveUploadFileset(mongoService, profileID, theProject, tree_Node, null, listTempDirs);
|
2022-05-20 12:31:58 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on uploading files: ", e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on uploading files, try again or contact the support. Error: " + e.getMessage());
|
|
|
|
}
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
try {
|
2022-10-06 11:25:31 +02:00
|
|
|
|
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
LOG.info("stepsOnPostCreation are {}", stepsOnPostCreation);
|
|
|
|
for (String stepID : stepsOnPostCreation) {
|
|
|
|
LOG.info("calling step OnPostCreation are {}", stepID);
|
|
|
|
theProject = client.performStep(theProject.getProfileID(), theProject.getId(), stepID, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new Exception("Error occurred on performing steps " + stepsOnPostCreation + " on the project: "
|
|
|
|
+ theProject.getId() + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2022-05-20 12:31:58 +02:00
|
|
|
LifecycleInformation lifecycleInfo = theProject.getLifecycleInformation();
|
|
|
|
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lifecycleInfo);
|
2022-10-19 11:42:37 +02:00
|
|
|
|
2022-09-01 12:44:00 +02:00
|
|
|
return new CommitReport(theProject.getId(), theProject.getProfileID(), theProject.getTheDocument().toJson(),
|
|
|
|
liDV);
|
2020-12-01 18:15:13 +01:00
|
|
|
} catch (Exception e) {
|
2022-08-05 12:44:33 +02:00
|
|
|
throw new Exception("Error occurred on loading LifecycleInformation for the project: " + theProject.getId()
|
|
|
|
+ ". Error: " + e.getMessage());
|
2022-10-20 16:58:29 +02:00
|
|
|
} finally {
|
2022-11-09 15:12:42 +01:00
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
LOG.debug("List listTempDirs is: " + listTempDirs);
|
|
|
|
if (listTempDirs != null && listTempDirs.size() > 0) {
|
|
|
|
for (File file : listTempDirs) {
|
|
|
|
try {
|
|
|
|
String dirName = file.getName();
|
|
|
|
LOG.debug("Deleting directory directory: " + dirName);
|
|
|
|
FileUtils.deleteDirectory(file);
|
|
|
|
LOG.debug("Directory {} deleted!", dirName);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.debug("Error on deleting the directory: " + file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
2022-05-20 12:31:58 +02:00
|
|
|
}
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
/**
|
|
|
|
* Update geportal data form.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @param section the section
|
|
|
|
* @param sectionPath the section path
|
|
|
|
* @param listFilePaths the list file paths
|
|
|
|
* @return the commit report
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2023-04-17 16:03:40 +02:00
|
|
|
@Override
|
|
|
|
public CommitReport updateGeportalDataForm(String profileID, String projectID, GeoNaFormDataObject section,
|
|
|
|
String sectionPath, List<FilePathDV> listFilePaths) throws Exception {
|
|
|
|
LOG.info("updateGeonaDataForm called for profileID {}", profileID);
|
|
|
|
LOG.info("and sectionPath {}", sectionPath);
|
|
|
|
LOG.info("and listFilePaths {}", listFilePaths);
|
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
ProjectsCaller client = null;
|
|
|
|
Project currentProject = null;
|
|
|
|
JSONObject updatedSectionObject = null;
|
|
|
|
Configuration configurationGson = null;
|
|
|
|
GenericDatasetBean sectionBean = null;
|
2023-04-17 16:03:40 +02:00
|
|
|
try {
|
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
if (projectID == null)
|
|
|
|
throw new Exception("projectID is null");
|
|
|
|
|
|
|
|
if (profileID == null)
|
|
|
|
throw new Exception("profileID is null");
|
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
if (section == null || section.getListGDB() == null || section.getListGDB().get(0) == null)
|
|
|
|
throw new Exception("Input error. The section is null");
|
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
sectionBean = section.getListGDB().get(0);
|
2023-04-17 16:03:40 +02:00
|
|
|
|
|
|
|
// Converter
|
|
|
|
FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON();
|
|
|
|
// JSON Section to update converted as JSONObject
|
2023-04-26 17:01:08 +02:00
|
|
|
updatedSectionObject = metadataConverter.genericDatasetBeanToJSON(sectionBean);
|
2023-04-20 16:34:52 +02:00
|
|
|
LOG.info("Input Json Section (to update): {}", updatedSectionObject.toString());
|
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
configurationGson = Configuration.builder().jsonProvider(new GsonJsonProvider()).build();
|
2023-04-17 16:03:40 +02:00
|
|
|
// Type type = new TypeToken<Set<LinkedTreeMap<String, Object>>>() {}.getType();
|
|
|
|
// Set<LinkedTreeMap<String, Object>> myMap = gson.fromJson(json, type);
|
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on converting form data: ", e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on converting data, try again or contact the support. Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean errorOccurred = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
currentProject = client.getProjectByID(profileID, projectID);
|
|
|
|
Document currentDoc = currentProject.getTheDocument();
|
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
// Source Project
|
2023-04-26 17:01:08 +02:00
|
|
|
String theDocumentJson = currentDoc.toJson();
|
|
|
|
LOG.debug("Source document: {}", theDocumentJson);
|
2023-04-20 16:34:52 +02:00
|
|
|
|
|
|
|
// If the section path is the Root document, passed as "$.", fixing as "$"
|
|
|
|
if (sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0)
|
2023-04-17 16:03:40 +02:00
|
|
|
sectionPath = FormDataObjectToJSON.JSON_$_POINTER;
|
2023-04-20 16:34:52 +02:00
|
|
|
|
|
|
|
com.google.gson.JsonObject targetSectionJObject = JsonPath.parse(theDocumentJson, configurationGson)
|
|
|
|
.read(sectionPath);
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.debug("Current Section path {} in the Document is {}", sectionPath, targetSectionJObject.toString());
|
2023-04-20 16:34:52 +02:00
|
|
|
String srcJ = updatedSectionObject.toString();
|
|
|
|
String trgJ = targetSectionJObject.toString();
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.debug("Merging src {} in the target: {}", srcJ, trgJ);
|
2023-04-21 15:27:29 +02:00
|
|
|
String mergedDoc = JsonMerge.merge(srcJ, trgJ, MERGE_OPTION.REPLACE);
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.debug("mergedDoc: {}", mergedDoc);
|
2023-04-20 16:34:52 +02:00
|
|
|
|
|
|
|
String newDocJson;
|
|
|
|
// If Updating path is first level of the root
|
|
|
|
if (sectionPath.equals(FormDataObjectToJSON.JSON_$_POINTER)) {
|
|
|
|
// The merged DOC is the root Document, no action required
|
|
|
|
newDocJson = mergedDoc;
|
|
|
|
} else {
|
|
|
|
// If the merged DOC is a child of the root Document, setting it as child of the
|
|
|
|
// Document in the proper section
|
|
|
|
Gson gson = new Gson();
|
|
|
|
JsonObject gsonOject = gson.fromJson(mergedDoc, JsonObject.class);
|
|
|
|
// Putting the merged section into Document
|
|
|
|
DocumentContext newContextDocJson = JsonPath.parse(theDocumentJson, configurationGson).set(sectionPath,
|
|
|
|
gsonOject);
|
|
|
|
newDocJson = newContextDocJson.json().toString();
|
2023-04-17 16:03:40 +02:00
|
|
|
|
2023-04-20 16:34:52 +02:00
|
|
|
}
|
2023-04-17 16:03:40 +02:00
|
|
|
|
2023-04-20 16:34:52 +02:00
|
|
|
Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class);
|
|
|
|
LOG.info("New document is: {}", updatedDocument.toJson());
|
2023-04-17 16:03:40 +02:00
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
Project updatedProject = client.updateProject(profileID, projectID, updatedDocument);
|
2023-04-21 16:34:11 +02:00
|
|
|
// Project project = client.getProjectByID(profileID, projectID);
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.debug("Medatata Updated with document: {}", updatedProject.getTheDocument());
|
2023-04-20 16:34:52 +02:00
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2023-04-20 16:34:52 +02:00
|
|
|
|
2023-04-21 16:34:11 +02:00
|
|
|
if (listFilePaths != null) {
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
// Collecting new files
|
|
|
|
List<? extends FileUploaded> filesUploaded = sectionBean.getFilesUploaded();
|
|
|
|
Map<String, FileSetDataObject> mapFilesToRegistrer = null;
|
|
|
|
if (filesUploaded != null && !filesUploaded.isEmpty()) {
|
|
|
|
mapFilesToRegistrer = collectFiles(currentProject, sectionPath, section.getGcubeProfileDV(),
|
|
|
|
filesUploaded);
|
|
|
|
}
|
|
|
|
|
2023-04-21 16:34:11 +02:00
|
|
|
// Cleaning all the fileset path of the section (defined in the UCD)
|
|
|
|
for (FilePathDV filePath : listFilePaths) {
|
|
|
|
|
2023-04-21 15:27:29 +02:00
|
|
|
String filesetFieldName = filePath.getFieldName();
|
2023-04-21 16:34:11 +02:00
|
|
|
String filesetPath = sectionPath + "." + filesetFieldName;
|
2023-05-02 11:34:53 +02:00
|
|
|
// // Replacing $.abc with $..abc
|
|
|
|
// filesetPath = filesetPath.replaceFirst("\\.", "..");
|
2023-04-21 15:27:29 +02:00
|
|
|
LOG.info("Going to delete fileset path: {}", filesetPath);
|
2023-04-21 16:34:11 +02:00
|
|
|
try {
|
2023-04-26 17:01:08 +02:00
|
|
|
client.deleteFileset(profileID, projectID, filesetPath, true, true);
|
2023-04-21 16:34:11 +02:00
|
|
|
} catch (Exception e) {
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.warn("Error deleting the fileset path {} for the project {}", filesetPath, projectID);
|
2023-04-21 16:34:11 +02:00
|
|
|
}
|
2023-04-21 15:27:29 +02:00
|
|
|
}
|
2023-04-21 16:34:11 +02:00
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
// Registering fileset in the section according to mapFilesToRegistrer
|
|
|
|
if (mapFilesToRegistrer != null && mapFilesToRegistrer.size()>0) {
|
|
|
|
LOG.info("Cluster of fileset per fieldDefinition is: " + mapFilesToRegistrer);
|
|
|
|
String theJSONDocument = currentProject.getTheDocument().toJson();
|
|
|
|
MongoServiceUtil mongoService = new MongoServiceUtil();
|
|
|
|
|
|
|
|
for (String fieldDefinition : mapFilesToRegistrer.keySet()) {
|
|
|
|
FileSetDataObject uploadedFileset = mapFilesToRegistrer.get(fieldDefinition);
|
|
|
|
LOG.info("Uploading fileset: " + uploadedFileset);
|
|
|
|
File[] fileset = uploadedFileset.getFileset();
|
|
|
|
FilePathDV filePath = uploadedFileset.getFilePathDV();
|
|
|
|
Access access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,
|
|
|
|
sectionPath);
|
|
|
|
|
|
|
|
LOG.info("Going to register fileset: " + Arrays.asList(fileset).toString());
|
|
|
|
mongoService.registerFileSet(currentProject.getProfileID(), currentProject, sectionPath,
|
|
|
|
filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
|
|
|
|
|
|
|
|
}
|
2023-04-21 15:27:29 +02:00
|
|
|
}
|
2023-05-02 15:16:59 +02:00
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
}
|
2023-04-21 16:34:11 +02:00
|
|
|
|
2023-04-26 17:01:08 +02:00
|
|
|
LOG.info("Project with id " + currentProject.getId() + " updated correclty");
|
2023-04-17 16:03:40 +02:00
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
2023-04-26 17:01:08 +02:00
|
|
|
// Reading again the project to be sure
|
|
|
|
updatedProject = client.getProjectByID(profileID, projectID);
|
|
|
|
ProjectDV toProjectDV = ConvertToDataValueObjectModel.toProjectDV(updatedProject, projectBuilder);
|
2023-04-20 16:34:52 +02:00
|
|
|
String newDocumentString = toProjectDV.getTheDocument().getDocumentAsJSON();
|
2023-04-17 16:03:40 +02:00
|
|
|
LOG.info("Got Document: {} ", newDocumentString);
|
|
|
|
return new CommitReport(projectID, profileID, newDocumentString, null);
|
|
|
|
} catch (Exception e) {
|
2023-04-26 17:01:08 +02:00
|
|
|
errorOccurred = true;
|
|
|
|
LOG.error("Error on updating data: ", e);
|
|
|
|
throw new Exception("Error occurred on updating data, try again or contact the support. Error: "
|
|
|
|
+ e.getMessage() + ". Tried to revert the project to the previous version");
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
// If an error occurs on updating, the previous version of the document will be
|
|
|
|
// restored
|
|
|
|
if (errorOccurred && currentProject != null) {
|
|
|
|
Document currentDocument = currentProject.getTheDocument();
|
|
|
|
try {
|
|
|
|
Project updatedProject = client.updateProject(profileID, projectID, currentDocument);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// Silent
|
|
|
|
}
|
|
|
|
}
|
2023-04-17 16:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-03 17:50:47 +02:00
|
|
|
/**
|
2022-08-05 12:44:33 +02:00
|
|
|
* Recursive upload fileset.
|
2022-08-03 17:50:47 +02:00
|
|
|
*
|
2022-08-05 12:44:33 +02:00
|
|
|
* @param mongoService the mongo service
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param theProject the the project
|
|
|
|
* @param tree_Node the tree node
|
|
|
|
* @param sectionJSONPathIndexer the json path indexer
|
2022-11-17 11:53:11 +01:00
|
|
|
* @param tempDirs the temp dirs
|
|
|
|
* @return the list
|
2022-08-03 17:50:47 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-10-20 16:58:29 +02:00
|
|
|
public List<File> recursiveUploadFileset(MongoServiceUtil mongoService, String profileID, Project theProject,
|
|
|
|
Tree_Node<GeoNaFormDataObject> tree_Node, Map<String, Integer> sectionJSONPathIndexer, List<File> tempDirs)
|
|
|
|
throws Exception {
|
2022-08-05 12:44:33 +02:00
|
|
|
LOG.debug("recursiveUploadFileset called [tree_Node: " + tree_Node + "], [jsonPathIndexer: "
|
|
|
|
+ sectionJSONPathIndexer + "]");
|
|
|
|
|
|
|
|
if (tree_Node == null)
|
2022-10-20 16:58:29 +02:00
|
|
|
return tempDirs;
|
2022-08-05 12:44:33 +02:00
|
|
|
|
|
|
|
if (sectionJSONPathIndexer == null) {
|
|
|
|
sectionJSONPathIndexer = new HashMap<String, Integer>();
|
|
|
|
}
|
|
|
|
|
2023-02-09 15:53:44 +01:00
|
|
|
String theJSONDocument = theProject.getTheDocument().toJson();
|
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
for (Tree_Node<GeoNaFormDataObject> treeNodeChild_GNA_DO : tree_Node.getChildren()) {
|
|
|
|
LOG.debug("Going to upload the files of tree node: " + treeNodeChild_GNA_DO);
|
|
|
|
|
|
|
|
// list GDB has always one element in the current implementation. One GDB per
|
|
|
|
// web-form/profile
|
|
|
|
List<GenericDatasetBean> listGDB = treeNodeChild_GNA_DO.getData().getListGDB();
|
|
|
|
GcubeProfileDV profile = treeNodeChild_GNA_DO.getData().getGcubeProfileDV();
|
|
|
|
|
|
|
|
// Building JSON/section full PATH and section name
|
|
|
|
String sectionJSONPath = "";
|
|
|
|
String parentPathIntoProfile = profile.getParentName() == null ? "" : profile.getParentName();
|
|
|
|
String theSectionName = profile.getSectionName();
|
|
|
|
|
|
|
|
if (theSectionName.compareTo(FormDataObjectToJSON.JSON_$_POINTER) == 0
|
|
|
|
|| theSectionName.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0) {
|
|
|
|
sectionJSONPath = FormDataObjectToJSON.JSON_$_POINTER;
|
|
|
|
theSectionName = "";
|
|
|
|
} else {
|
|
|
|
sectionJSONPath = String.format("%s%s",
|
|
|
|
parentPathIntoProfile.endsWith(".") ? parentPathIntoProfile : parentPathIntoProfile + ".",
|
|
|
|
theSectionName);
|
|
|
|
}
|
2022-08-03 17:50:47 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
LOG.debug("The sectionJSONPath is: " + sectionJSONPath);
|
2022-08-03 17:50:47 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
Integer jpcV = sectionJSONPathIndexer.get(sectionJSONPath);
|
|
|
|
if (jpcV == null) {
|
|
|
|
jpcV = 0;
|
|
|
|
sectionJSONPathIndexer.put(sectionJSONPath, jpcV);
|
|
|
|
} else {
|
|
|
|
jpcV = jpcV + 1;
|
|
|
|
sectionJSONPathIndexer.put(sectionJSONPath, jpcV);
|
|
|
|
}
|
|
|
|
LOG.debug("sectionJSONPathIndexer is: " + sectionJSONPathIndexer);
|
2022-08-03 17:50:47 +02:00
|
|
|
LOG.info("The profile is: " + profile);
|
|
|
|
for (GenericDatasetBean gdb : listGDB) {
|
2022-08-05 12:44:33 +02:00
|
|
|
Map<String, FileSetDataObject> collectFilesetPerFieldDef = new HashMap<String, FileSetDataObject>();
|
2022-08-03 17:50:47 +02:00
|
|
|
List<FileUploaded> files = gdb.getFilesUploaded();
|
|
|
|
if (files.size() > 0) {
|
2022-08-05 12:44:33 +02:00
|
|
|
// Iterating on the files upload for the section
|
2022-08-03 17:50:47 +02:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
FileUploaded file = files.get(i);
|
|
|
|
String formFieldName = file.getFilePath().getFormFieldLabel();
|
|
|
|
LOG.debug("Uploading file: " + file.getFileName() + ", from formFieldName: " + formFieldName);
|
|
|
|
FilePathDV filePath = retrieveFilePathForGcubeProfileFieldName(formFieldName, profile);
|
|
|
|
LOG.info("Found {} for the form fieldName {}", filePath, formFieldName);
|
|
|
|
if (filePath == null) {
|
|
|
|
String error = "It is not possible to register the file " + formFieldName
|
|
|
|
+ ", missing configuration in the filePaths config of: " + profile;
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
// Collecting Fileset per Field Definition
|
|
|
|
FileSetDataObject collFieldDef = collectFilesetPerFieldDef.get(filePath.getFieldDefinition());
|
|
|
|
if (collFieldDef == null) {
|
|
|
|
collFieldDef = new FileSetDataObject();
|
|
|
|
collFieldDef.setFilePathDV(filePath);
|
|
|
|
}
|
2022-10-20 16:58:29 +02:00
|
|
|
|
2022-10-19 11:42:37 +02:00
|
|
|
try {
|
|
|
|
File input = new File(file.getTempSystemPath());
|
2022-10-20 16:58:29 +02:00
|
|
|
LOG.debug("Temp file is: " + file.getTempSystemPath());
|
|
|
|
File tempDir = Files.createTempDirectory("GEOPORTAL_UPLOAD_").toFile();
|
|
|
|
|
|
|
|
String tmpDirPath = tempDir.getAbsolutePath();
|
|
|
|
File output = new File(tmpDirPath, file.getFileName());
|
|
|
|
// input.renameTo(output);
|
2022-10-19 11:42:37 +02:00
|
|
|
copyContent(input, output);
|
|
|
|
collFieldDef.addFile(output);
|
2022-10-20 16:58:29 +02:00
|
|
|
tempDirs.add(tempDir);
|
|
|
|
tempDir.deleteOnExit();
|
|
|
|
LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: "
|
|
|
|
+ file.getFileName());
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
|
2022-10-19 11:42:37 +02:00
|
|
|
}
|
2022-10-20 16:58:29 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-08-03 17:50:47 +02:00
|
|
|
|
2022-08-05 12:44:33 +02:00
|
|
|
LOG.info("Cluster of fileset per fieldDefinition is: " + collectFilesetPerFieldDef);
|
|
|
|
|
|
|
|
for (String fieldDefinition : collectFilesetPerFieldDef.keySet()) {
|
|
|
|
FileSetDataObject uploadedFileset = collectFilesetPerFieldDef.get(fieldDefinition);
|
|
|
|
LOG.info("Uploading fileset: " + uploadedFileset);
|
|
|
|
|
|
|
|
File[] fileset = uploadedFileset.getFileset();
|
|
|
|
FilePathDV filePath = uploadedFileset.getFilePathDV();
|
|
|
|
|
2023-02-09 15:53:44 +01:00
|
|
|
Access access;
|
2022-08-05 12:44:33 +02:00
|
|
|
// If the maxOccurs is not 1
|
|
|
|
if (profile.getMaxOccurs() == 0 || profile.getMaxOccurs() > 1) {
|
|
|
|
LOG.info("The gCube Profile with the section " + sectionJSONPath
|
|
|
|
+ " has maxOccurs > 1 need to manage it as array, going to add the array index");
|
|
|
|
String arraySectionJSONPAth = String.format("%s[%d]", sectionJSONPath, jpcV);
|
|
|
|
LOG.debug("registering the fileset in the array section: " + sectionJSONPath);
|
2023-04-17 16:03:40 +02:00
|
|
|
|
|
|
|
access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,
|
|
|
|
arraySectionJSONPAth);
|
2022-08-05 12:44:33 +02:00
|
|
|
mongoService.registerFileSet(profileID, theProject, arraySectionJSONPAth,
|
2023-02-09 15:53:44 +01:00
|
|
|
filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
|
2022-08-05 12:44:33 +02:00
|
|
|
} else {
|
|
|
|
LOG.info("The gCube Profile with the section " + sectionJSONPath + " has maxOccurs = 1");
|
|
|
|
LOG.debug("registering the fileset in the section: " + sectionJSONPath);
|
2023-04-17 16:03:40 +02:00
|
|
|
access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,
|
|
|
|
sectionJSONPath);
|
2022-08-05 12:44:33 +02:00
|
|
|
mongoService.registerFileSet(profileID, theProject, sectionJSONPath, filePath.getFieldName(),
|
2023-02-09 15:53:44 +01:00
|
|
|
filePath.getFieldDefinition(), access, fileset);
|
2022-08-03 17:50:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-08-05 12:44:33 +02:00
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
tempDirs = recursiveUploadFileset(mongoService, profileID, theProject, treeNodeChild_GNA_DO,
|
|
|
|
sectionJSONPathIndexer, tempDirs);
|
2022-08-03 17:50:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
return tempDirs;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
/**
|
|
|
|
* Collect files.
|
|
|
|
*
|
|
|
|
* @param theProject the the project
|
|
|
|
* @param sectionJSONPath the section JSON path
|
|
|
|
* @param gcubeProfile the gcube profile
|
|
|
|
* @param files the files
|
|
|
|
* @return the map of files that must be registered
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
protected Map<String, FileSetDataObject> collectFiles(Project theProject, String sectionJSONPath,
|
|
|
|
GcubeProfileDV gcubeProfile, List<? extends FileUploaded> files) throws Exception {
|
|
|
|
LOG.debug("collectFiles called [projectID: " + theProject.getId() + "], [sectionJSONPath: " + sectionJSONPath
|
|
|
|
+ "], [files: " + files + "]");
|
|
|
|
|
|
|
|
Map<String, FileSetDataObject> collectFilesetPerFieldDef = new HashMap<String, FileSetDataObject>();
|
|
|
|
if (files.size() > 0) {
|
|
|
|
// Iterating on the files upload for the section
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
FileUploaded file = files.get(i);
|
|
|
|
String formFieldName = file.getFilePath().getFormFieldLabel();
|
|
|
|
LOG.debug("Uploading file: " + file.getFileName() + ", from formFieldName: " + formFieldName);
|
|
|
|
FilePathDV filePath = retrieveFilePathForGcubeProfileFieldName(formFieldName, gcubeProfile);
|
|
|
|
LOG.info("Found {} for the form fieldName {}", filePath, formFieldName);
|
|
|
|
if (filePath == null) {
|
|
|
|
String error = "It is not possible to register the file " + formFieldName
|
|
|
|
+ ", missing configuration in the filePaths config of: " + gcubeProfile;
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collecting Fileset per Field Definition
|
|
|
|
FileSetDataObject collFieldDef = collectFilesetPerFieldDef.get(filePath.getFieldDefinition());
|
|
|
|
if (collFieldDef == null) {
|
|
|
|
collFieldDef = new FileSetDataObject();
|
|
|
|
collFieldDef.setFilePathDV(filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
File tempDir = Files.createTempDirectory("GEOPORTAL_REPLACE_FILES_").toFile();
|
|
|
|
String tmpDirPath = tempDir.getAbsolutePath();
|
|
|
|
File input;
|
|
|
|
File output;
|
|
|
|
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();
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
collFieldDef.addFile(output);
|
|
|
|
tempDir.deleteOnExit();
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return collectFilesetPerFieldDef;
|
|
|
|
}
|
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
/**
|
|
|
|
* Replace files.
|
|
|
|
*
|
|
|
|
* @param theProject the the project
|
|
|
|
* @param sectionJSONPath the section JSON path
|
|
|
|
* @param gcubeProfile the gcube profile
|
|
|
|
* @param files the files
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
protected void replaceFiles(Project theProject, String sectionJSONPath, GcubeProfileDV gcubeProfile,
|
|
|
|
List<? extends FileUploaded> files) throws Exception {
|
|
|
|
LOG.debug("replaceFiles called [projectID: " + theProject.getId() + "], [sectionJSONPath: " + sectionJSONPath
|
|
|
|
+ "], [files: " + files + "]");
|
|
|
|
|
|
|
|
Map<String, FileSetDataObject> collectFilesetPerFieldDef = new HashMap<String, FileSetDataObject>();
|
|
|
|
if (files.size() > 0) {
|
|
|
|
// Iterating on the files upload for the section
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
FileUploaded file = files.get(i);
|
|
|
|
String formFieldName = file.getFilePath().getFormFieldLabel();
|
|
|
|
LOG.debug("Uploading file: " + file.getFileName() + ", from formFieldName: " + formFieldName);
|
|
|
|
FilePathDV filePath = retrieveFilePathForGcubeProfileFieldName(formFieldName, gcubeProfile);
|
|
|
|
LOG.info("Found {} for the form fieldName {}", filePath, formFieldName);
|
|
|
|
if (filePath == null) {
|
|
|
|
String error = "It is not possible to register the file " + formFieldName
|
|
|
|
+ ", missing configuration in the filePaths config of: " + gcubeProfile;
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collecting Fileset per Field Definition
|
|
|
|
FileSetDataObject collFieldDef = collectFilesetPerFieldDef.get(filePath.getFieldDefinition());
|
|
|
|
if (collFieldDef == null) {
|
|
|
|
collFieldDef = new FileSetDataObject();
|
|
|
|
collFieldDef.setFilePathDV(filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
File tempDir = Files.createTempDirectory("GEOPORTAL_REPLACE_FILES_").toFile();
|
|
|
|
String tmpDirPath = tempDir.getAbsolutePath();
|
|
|
|
File input;
|
|
|
|
File output;
|
|
|
|
if (file instanceof FileUploadedRemote) {
|
|
|
|
FileUploadedRemote remote = (FileUploadedRemote) file;
|
|
|
|
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
|
|
|
InputStream in = new URL(remote.getUrl()).openStream();
|
2023-05-02 15:16:59 +02:00
|
|
|
String fileName = (remote.getFileName() == null || remote.getFileName().isEmpty())
|
|
|
|
? "file_" + Random.nextInt()
|
|
|
|
: remote.getFileName();
|
2023-05-02 11:34:53 +02:00
|
|
|
output = new File(tmpDirPath, fileName);
|
2023-04-17 16:03:40 +02:00
|
|
|
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);
|
2023-04-20 16:34:52 +02:00
|
|
|
LOG.info(
|
|
|
|
"Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName());
|
2023-04-17 16:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
collFieldDef.addFile(output);
|
|
|
|
tempDir.deleteOnExit();
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG.info("Cluster of fileset per fieldDefinition is: " + collectFilesetPerFieldDef);
|
|
|
|
String theJSONDocument = theProject.getTheDocument().toJson();
|
|
|
|
MongoServiceUtil mongoService = new MongoServiceUtil();
|
|
|
|
|
|
|
|
for (String fieldDefinition : collectFilesetPerFieldDef.keySet()) {
|
|
|
|
FileSetDataObject uploadedFileset = collectFilesetPerFieldDef.get(fieldDefinition);
|
|
|
|
LOG.info("Uploading fileset: " + uploadedFileset);
|
|
|
|
File[] fileset = uploadedFileset.getFileset();
|
|
|
|
FilePathDV filePath = uploadedFileset.getFilePathDV();
|
|
|
|
Access access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument, sectionJSONPath);
|
2023-04-20 16:34:52 +02:00
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
LOG.info("Going to register files: " + Arrays.asList(fileset).toString());
|
2023-04-21 16:34:11 +02:00
|
|
|
mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath,
|
|
|
|
filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
|
2023-04-17 16:03:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 16:58:29 +02:00
|
|
|
/**
|
|
|
|
* Creates the temp file on storage.
|
|
|
|
*
|
|
|
|
* @param is the is
|
|
|
|
* @param fileName the file name
|
|
|
|
* @return the temp file
|
|
|
|
*/
|
|
|
|
public TempFile createTempFileOnStorage(InputStream is, String fileName) {
|
|
|
|
LOG.debug("createTempFileOnStorage called");
|
|
|
|
StorageUtils storage = new StorageUtils();
|
|
|
|
TempFile toUpload = null;
|
|
|
|
try {
|
|
|
|
LOG.info("calling putOntoStorage the stream with the fileName: " + fileName);
|
|
|
|
toUpload = storage.putOntoStorage(is, fileName);
|
|
|
|
} catch (RemoteBackendException | FileNotFoundException e) {
|
|
|
|
LOG.error("Error when uploading stream on Storage: ", e);
|
|
|
|
}
|
|
|
|
return toUpload;
|
2022-08-03 17:50:47 +02:00
|
|
|
}
|
|
|
|
|
2022-11-17 11:53:11 +01:00
|
|
|
/**
|
|
|
|
* Copy content.
|
|
|
|
*
|
|
|
|
* @param a the a
|
|
|
|
* @param b the b
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-10-19 11:42:37 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2022-10-20 16:58:29 +02:00
|
|
|
LOG.debug("File Copied");
|
2022-10-19 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2022-08-03 17:50:47 +02:00
|
|
|
/**
|
|
|
|
* Retrieve file path for gcube profile field name.
|
|
|
|
*
|
|
|
|
* @param fieldName the field name
|
|
|
|
* @param profile the profile
|
|
|
|
* @return the file path DV
|
|
|
|
*/
|
2022-05-20 12:31:58 +02:00
|
|
|
public static FilePathDV retrieveFilePathForGcubeProfileFieldName(String fieldName, GcubeProfileDV profile) {
|
|
|
|
LOG.debug("Searching fieldDefinition for fieldName {} in the FilePaths {}", fieldName, profile.getFilePaths());
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2022-05-20 12:31:58 +02:00
|
|
|
if (fieldName == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
for (FilePathDV path : profile.getFilePaths()) {
|
|
|
|
if (path.getGcubeProfileFieldName().equals(fieldName)) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
2020-12-01 18:15:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the geona init config.
|
|
|
|
*
|
|
|
|
* @return the geona init config
|
|
|
|
*/
|
2020-10-21 15:36:50 +02:00
|
|
|
@Override
|
2022-09-26 16:17:41 +02:00
|
|
|
public GeoportalISConfig getGeonaInitConfig() {
|
2020-10-21 15:36:50 +02:00
|
|
|
LOG.info("getConfig called");
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2020-10-21 15:36:50 +02:00
|
|
|
String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), false);
|
|
|
|
String theSecondaryType;
|
|
|
|
try {
|
|
|
|
theSecondaryType = this.getServletContext().getInitParameter(GEONA_GENERIC_RESOURCE_SECONDARY_TYPE);
|
|
|
|
} catch (Exception e) {
|
2021-12-22 12:20:08 +01:00
|
|
|
LOG.warn("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e);
|
2020-10-21 15:36:50 +02:00
|
|
|
theSecondaryType = "GeoNaMetadata";
|
2021-12-22 12:20:08 +01:00
|
|
|
LOG.warn("Using default SecondaryType: " + theSecondaryType);
|
2020-10-21 15:36:50 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 12:14:57 +01:00
|
|
|
// LOG.warn("\n\n\nHARD-CABLING THE SCOPE, PLEASE REMOTE IT!!!!\n\n\n");
|
|
|
|
// scope = "/gcube/devsec/devVRE";
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2022-09-26 16:17:41 +02:00
|
|
|
GeoportalISConfig configs = new GeoportalISConfig(theSecondaryType, scope);
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.info("returning config: " + configs);
|
2020-10-21 15:36:50 +02:00
|
|
|
return configs;
|
|
|
|
}
|
2020-12-01 18:15:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the links for.
|
|
|
|
*
|
2022-08-03 17:50:47 +02:00
|
|
|
* @param itemId the item id is the mongoId
|
|
|
|
* @param profileID the profile ID
|
2020-12-01 18:15:13 +01:00
|
|
|
* @return the links for
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2022-10-18 16:38:48 +02:00
|
|
|
public GeoportalItemReferences getLinksFor(String itemId, String profileID) throws Exception {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.info("getLinksFor called");
|
|
|
|
|
2023-05-03 10:04:48 +02:00
|
|
|
String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
//GNADataViewerConfigProfile grViewerProfile = SessionUtil.getGeportalViewerResourceProfile(getThreadLocalRequest());
|
|
|
|
GeoportalCommon gc = new GeoportalCommon();
|
2022-10-18 16:38:48 +02:00
|
|
|
GeoportalItemReferences item = new GeoportalItemReferences(itemId, profileID);
|
2023-05-03 10:04:48 +02:00
|
|
|
item = gc.getPublicLinksFor(scope, item, true);
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.info("Returning: " + item);
|
|
|
|
return item;
|
|
|
|
}
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2021-07-23 17:40:50 +02:00
|
|
|
/**
|
2022-03-17 18:08:58 +01:00
|
|
|
* Gets the list projects.
|
2021-07-23 17:40:50 +02:00
|
|
|
*
|
2022-08-03 17:50:47 +02:00
|
|
|
* @param theProfileID the the profile ID
|
2021-12-06 17:24:27 +01:00
|
|
|
* @param start the start
|
2021-08-05 16:49:04 +02:00
|
|
|
* @param limit the limit
|
2021-08-06 16:23:17 +02:00
|
|
|
* @param filter the filter
|
|
|
|
* @param reloadFromService the reload from service
|
2022-03-17 18:08:58 +01:00
|
|
|
* @return the list projects
|
2021-07-23 17:40:50 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-12-06 17:24:27 +01:00
|
|
|
@Override
|
2022-03-17 18:08:58 +01:00
|
|
|
public ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit,
|
|
|
|
SearchingFilter filter, boolean reloadFromService) throws Exception {
|
|
|
|
LOG.info("getListProjects called with profileID: " + theProfileID + ", start: " + start + ", limit: " + limit
|
|
|
|
+ ", filter: " + filter);
|
2021-07-23 17:40:50 +02:00
|
|
|
|
2021-08-02 12:52:30 +02:00
|
|
|
try {
|
2021-12-01 11:54:39 +01:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
2021-12-06 17:24:27 +01:00
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2021-08-04 17:11:46 +02:00
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
ResultSetPaginatedData searchedData = new ResultSetPaginatedData();
|
|
|
|
|
2023-04-17 16:03:40 +02:00
|
|
|
// If reloadFromService = true, loads the document from the service
|
2023-03-06 15:40:28 +01:00
|
|
|
Integer totalProjectForProfile = null;
|
2023-04-17 16:03:40 +02:00
|
|
|
|
|
|
|
// Loading total documents from the session
|
|
|
|
if (!reloadFromService) {
|
2023-03-06 15:40:28 +01:00
|
|
|
totalProjectForProfile = SessionUtil.getTotalDocumentForProfileID(getThreadLocalRequest(),
|
2023-04-17 16:03:40 +02:00
|
|
|
theProfileID);
|
2023-03-06 15:40:28 +01:00
|
|
|
}
|
2022-03-17 18:08:58 +01:00
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
if (totalProjectForProfile == null) {
|
|
|
|
totalProjectForProfile = client.getTotalDocument(theProfileID);
|
|
|
|
SessionUtil.setTotalDocumentForProfileID(getThreadLocalRequest(), theProfileID, totalProjectForProfile);
|
|
|
|
}
|
2022-03-17 18:08:58 +01:00
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
searchedData.setTotalItems(totalProjectForProfile);
|
2022-08-11 12:07:07 +02:00
|
|
|
LOG.info("Total Docs read from config: " + totalProjectForProfile);
|
2023-02-09 15:53:44 +01:00
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
// Saving client PROJECTION
|
|
|
|
LinkedHashMap<String, Object> originalProjection = filter.getProjection();
|
|
|
|
int totalItems = totalProjectForProfile;
|
2023-02-09 15:53:44 +01:00
|
|
|
// PERFORMING FIRST QUERY FOR IDS IF AND ONLY IF WHERE CONDITIONS IN THE QUERY.
|
|
|
|
// SEARCHING FACILITY IS ENACTING.
|
|
|
|
if (filter.getConditions() != null) {
|
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
// Setting PROJECTION ONLY FOR PROEJCT ID
|
|
|
|
LinkedHashMap<String, Object> projectionForIDs = new LinkedHashMap<String, Object>();
|
|
|
|
projectionForIDs.put(Project.ID, 1);
|
|
|
|
filter.setProjection(projectionForIDs);
|
2023-02-09 15:53:44 +01:00
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
// FIRST QUERY TO RETRIEVE IDs
|
|
|
|
// LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS
|
2023-02-09 15:53:44 +01:00
|
|
|
// Calculating always the size starting from 0
|
2022-11-30 09:45:36 +01:00
|
|
|
final Iterator<Project> projectsIDs = client.queryOnMongo(theProfileID, totalProjectForProfile, 0, null,
|
|
|
|
filter);
|
2023-02-09 15:53:44 +01:00
|
|
|
|
|
|
|
// Getting the Project IDs from the Iterable
|
2022-11-30 09:45:36 +01:00
|
|
|
Iterable<Project> itP = () -> projectsIDs;
|
|
|
|
Stream<Project> targetStream = StreamSupport.stream(itP.spliterator(), false);
|
|
|
|
List<String> listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList());
|
|
|
|
totalItems = listProjectIDs.size();
|
|
|
|
searchedData.setTotalItems(totalItems);
|
|
|
|
LOG.info("Total Docs read from query per ID: " + totalItems);
|
|
|
|
}
|
2023-02-09 15:53:44 +01:00
|
|
|
|
|
|
|
// NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT
|
2022-11-30 09:45:36 +01:00
|
|
|
// SETTING ORIGINAL PROJECTION FROM CLIENT
|
|
|
|
filter.setProjection(originalProjection);
|
|
|
|
// LIMIT IS FROM CLIENT
|
2023-02-09 15:53:44 +01:00
|
|
|
Iterator<Project> projects = client.queryOnMongo(theProfileID, totalItems, start, limit, filter);
|
2022-08-09 16:37:09 +02:00
|
|
|
|
2022-11-30 09:45:36 +01:00
|
|
|
searchedData.setClientStartIndex(start);
|
|
|
|
searchedData.setLimit(limit);
|
|
|
|
searchedData.setServerSearchFinished(false);
|
2022-03-17 18:08:58 +01:00
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
List<ResultDocumentDV> toReturnList = ConvertToDataValueObjectModel.toListResultDocument(projects);
|
|
|
|
searchedData.setData(toReturnList);
|
2023-02-09 15:53:44 +01:00
|
|
|
|
|
|
|
LOG.info(
|
|
|
|
"Total Docs page size returned:" + toReturnList.size() + ", start: " + start + ", limit: " + limit);
|
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
if (totalProjectForProfile == limit || totalProjectForProfile == 0) {
|
|
|
|
LOG.debug("Page completed returning " + totalProjectForProfile + " projects");
|
|
|
|
int newOffset = start + limit;
|
|
|
|
searchedData.setServerSearchFinished(newOffset > totalProjectForProfile || totalProjectForProfile == 0);
|
|
|
|
LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
|
2022-03-17 18:08:58 +01:00
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
}
|
2022-03-17 18:08:58 +01:00
|
|
|
|
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
LOG.debug("returning {}", searchedData.getData());
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:07:07 +02:00
|
|
|
List<? extends DocumentDV> data = searchedData.getData();
|
2022-03-17 18:08:58 +01:00
|
|
|
if (data != null) {
|
|
|
|
LOG.info("returning {} project/s", data.size());
|
|
|
|
}
|
2021-08-05 16:49:04 +02:00
|
|
|
|
2021-12-06 17:24:27 +01:00
|
|
|
return searchedData;
|
2021-08-04 17:11:46 +02:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.error("Error on loading paginated and filtered list of projects for id: ", e);
|
2022-10-18 15:30:12 +02:00
|
|
|
throw new Exception("Error occurred on loading list of Projects. Error: " + e.getMessage());
|
2021-08-02 12:52:30 +02:00
|
|
|
}
|
2021-07-23 17:40:50 +02:00
|
|
|
|
2021-08-02 12:52:30 +02:00
|
|
|
}
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2021-09-16 12:15:07 +02:00
|
|
|
/**
|
2022-09-01 16:43:25 +02:00
|
|
|
* Delete project.
|
2021-09-16 12:15:07 +02:00
|
|
|
*
|
2022-09-01 16:43:25 +02:00
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
2021-09-16 12:15:07 +02:00
|
|
|
* @return true, if successful
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-08-05 16:49:04 +02:00
|
|
|
@Override
|
2022-09-01 16:43:25 +02:00
|
|
|
public boolean deleteProject(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("deleteProject called for profileID {}, projectID {}", profileID, projectID);
|
2021-08-05 16:49:04 +02:00
|
|
|
try {
|
|
|
|
|
2022-09-01 16:43:25 +02:00
|
|
|
if (projectID == null)
|
|
|
|
throw new Exception("projectID is null");
|
2021-08-05 16:49:04 +02:00
|
|
|
|
2022-09-01 16:43:25 +02:00
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2021-08-05 16:49:04 +02:00
|
|
|
|
2023-02-09 15:53:44 +01:00
|
|
|
client.deleteProject(profileID, projectID, true);
|
2022-09-12 15:09:43 +02:00
|
|
|
// Updating count of Documents in session per profileID
|
2022-09-01 16:43:25 +02:00
|
|
|
Integer totalProjectForProfile = client.getTotalDocument(profileID);
|
|
|
|
SessionUtil.setTotalDocumentForProfileID(getThreadLocalRequest(), profileID, totalProjectForProfile);
|
|
|
|
return true;
|
2021-08-05 16:49:04 +02:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
2022-09-01 16:43:25 +02:00
|
|
|
LOG.error("Error on deleting the project with id: " + projectID, e);
|
2021-08-05 16:49:04 +02:00
|
|
|
throw new Exception(
|
2022-09-01 16:43:25 +02:00
|
|
|
"Error occurred on deleting the project with id: " + projectID + ". Error: " + e.getMessage());
|
2021-08-05 16:49:04 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-16 12:15:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update record.
|
|
|
|
*
|
2022-09-16 17:42:01 +02:00
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
2021-09-16 12:15:07 +02:00
|
|
|
* @param jsonUpdate the json update
|
2021-09-24 12:06:53 +02:00
|
|
|
* @return the updated JSON string representing the itemId
|
2021-09-16 12:15:07 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2022-09-14 10:12:07 +02:00
|
|
|
public ProjectDV updateRecord(String profileID, String projectID, String jsonUpdate) throws Exception {
|
|
|
|
LOG.info("updateRecord called with profileID: " + profileID + ", projectID: " + projectID);
|
2021-09-16 12:15:07 +02:00
|
|
|
try {
|
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
if (projectID == null)
|
|
|
|
throw new Exception("projectID is null");
|
2021-09-16 12:15:07 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2022-09-16 17:42:01 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
Document updatedDocument = Serialization.read(jsonUpdate, Document.class);
|
|
|
|
LOG.info("updatedDocument is {}", updatedDocument);
|
|
|
|
Project project = client.updateProject(profileID, projectID, updatedDocument);
|
|
|
|
LOG.info("Project with id " + project.getId() + " updated correclty");
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
return ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
2021-09-16 12:15:07 +02:00
|
|
|
} catch (Exception e) {
|
2022-09-14 10:12:07 +02:00
|
|
|
LOG.error("Error on updating the project with item id: " + projectID, e);
|
2021-09-16 12:15:07 +02:00
|
|
|
throw new Exception(
|
2022-09-14 10:12:07 +02:00
|
|
|
"Error occurred on updating the project with id: " + projectID + ". Error: " + e.getMessage());
|
2021-09-16 12:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-12 15:09:43 +02:00
|
|
|
* Gets the JSON document in the project.
|
2021-09-16 12:15:07 +02:00
|
|
|
*
|
2022-09-12 15:09:43 +02:00
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the JSON document in the project
|
2021-09-16 12:15:07 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2022-09-12 15:09:43 +02:00
|
|
|
public String getJSONDocumentInTheProject(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("getJSONDocumentInTheProject called with profileID: " + profileID + ", projectID: " + projectID);
|
2021-09-16 12:15:07 +02:00
|
|
|
try {
|
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
if (projectID == null)
|
|
|
|
throw new Exception("projectID is null");
|
2021-09-16 12:15:07 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
if (profileID == null)
|
|
|
|
throw new Exception("profileID is null");
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
Project project = client.getProjectByID(profileID, projectID);
|
2021-09-16 12:15:07 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
return project.getTheDocument().toJson();
|
2021-09-16 12:15:07 +02:00
|
|
|
} catch (Exception e) {
|
2022-09-12 15:09:43 +02:00
|
|
|
LOG.error("Error occurred on reading the JSON document in the project with ID: " + projectID, e);
|
|
|
|
throw new Exception("Error occurred on reading the JSON document in the project with ID: " + projectID
|
|
|
|
+ ". Error: " + e.getMessage());
|
2021-09-16 12:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-27 18:32:19 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
/**
|
|
|
|
* Read data viewer config.
|
|
|
|
*
|
|
|
|
* @return the GNA data entry ext config profile
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-11-26 16:05:05 +01:00
|
|
|
@Override
|
2022-09-26 16:17:41 +02:00
|
|
|
public GNADataEntryExtendedConfigProfile readDataViewerConfig() throws Exception {
|
2021-12-21 16:51:56 +01:00
|
|
|
LOG.info("readDataViewerConfig called");
|
2021-11-26 16:05:05 +01:00
|
|
|
|
|
|
|
GCubeUser user = null;
|
2022-09-26 16:17:41 +02:00
|
|
|
GNADataEntryExtendedConfigProfile gnaDEExtConfig = new GNADataEntryExtendedConfigProfile();
|
2021-11-26 16:05:05 +01:00
|
|
|
try {
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
user = pContext.getCurrentUser(this.getThreadLocalRequest());
|
2021-12-21 16:51:56 +01:00
|
|
|
String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
GNADataEntryConfigProfile config = getGNADataEntryConfigProfile();
|
2021-12-06 17:24:27 +01:00
|
|
|
List<RoleRights> listUserRightsForRole = config.getPermissionsForRole();
|
2021-12-21 16:51:56 +01:00
|
|
|
gnaDEExtConfig.setPermissionsForRole(listUserRightsForRole);
|
2022-09-26 16:17:41 +02:00
|
|
|
gnaDEExtConfig.setDataEntryGUIPresentation(config.getDataEntryGUIPresentation());
|
2021-12-21 16:51:56 +01:00
|
|
|
|
2021-11-26 16:05:05 +01:00
|
|
|
// DEV MODE
|
|
|
|
if (!SessionUtil.isIntoPortal()) {
|
|
|
|
LOG.warn("OUT OF PORTAL - DEV MODE detected");
|
2022-09-16 17:42:01 +02:00
|
|
|
GcubeUserRole myRole = GcubeUserRole.DATA_MANAGER;
|
2021-11-26 16:05:05 +01:00
|
|
|
|
|
|
|
for (RoleRights roleRight : listUserRightsForRole) {
|
|
|
|
if (roleRight.getUserRole().equals(myRole)) {
|
|
|
|
UserRights userRights = new UserRights(user.getUsername(), roleRight);
|
|
|
|
LOG.warn("DEV MODE returning: " + userRights);
|
2021-12-21 16:51:56 +01:00
|
|
|
gnaDEExtConfig.setUserRights(userRights);
|
|
|
|
return gnaDEExtConfig;
|
2021-11-26 16:05:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest());
|
|
|
|
|
|
|
|
if (user == null || scope == null) {
|
|
|
|
LOG.warn("called getMyRightsInTheContext with invalid parameter user: " + user + ", in the scope: "
|
|
|
|
+ scope, ", returning null");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG.info("reading GcubeUserRole for user: " + user.getUsername() + ", in the scope: " + scope);
|
|
|
|
// The following snippet should pass in the service-side
|
|
|
|
RoleManager roleManager = new LiferayRoleManager();
|
|
|
|
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), groupId);
|
|
|
|
List<GcubeUserRole> listMyRoles = new ArrayList<GcubeUserRole>();
|
|
|
|
for (GCubeRole gCubeRole : roles) {
|
|
|
|
if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_EDITOR.getName())) {
|
|
|
|
listMyRoles.add(GcubeUserRole.DATA_EDITOR);
|
|
|
|
}
|
|
|
|
if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_MANAGER.getName())) {
|
|
|
|
listMyRoles.add(GcubeUserRole.DATA_MANAGER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mapping to roles "known"
|
|
|
|
LOG.info(
|
|
|
|
"For user: " + user.getUsername() + " in the scope: " + scope + " read the role/s: " + listMyRoles);
|
|
|
|
|
|
|
|
GcubeUserRole myRole = null;
|
|
|
|
if (listMyRoles.contains(GcubeUserRole.DATA_MANAGER))
|
|
|
|
myRole = GcubeUserRole.DATA_MANAGER;
|
|
|
|
else if (listMyRoles.contains(GcubeUserRole.DATA_EDITOR))
|
|
|
|
myRole = GcubeUserRole.DATA_EDITOR;
|
|
|
|
else
|
|
|
|
myRole = GcubeUserRole.DATA_MEMBER;
|
|
|
|
|
|
|
|
LOG.info("using highest role: " + myRole);
|
|
|
|
|
|
|
|
RoleRights toRoleRight = null;
|
|
|
|
for (RoleRights roleRight : listUserRightsForRole) {
|
|
|
|
if (roleRight.getUserRole().equals(myRole)) {
|
|
|
|
toRoleRight = roleRight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 16:59:45 +01:00
|
|
|
UserRights userRights = new UserRights(user.getUsername(), toRoleRight);
|
2021-11-26 16:05:05 +01:00
|
|
|
LOG.info("returning: " + userRights);
|
2021-12-21 16:51:56 +01:00
|
|
|
gnaDEExtConfig.setUserRights(userRights);
|
|
|
|
return gnaDEExtConfig;
|
|
|
|
} catch (UserRetrievalFault | GroupRetrievalFault | GNAConfigException e) {
|
2021-11-26 16:05:05 +01:00
|
|
|
LOG.error("An error occurred during getMyRightsInTheContext: " + user, e);
|
|
|
|
|
2022-09-13 13:52:44 +02:00
|
|
|
Map<OPERATION_ON_ITEM, OPERATION_TYPE> permissions = new HashMap<OPERATION_ON_ITEM, RoleRights.OPERATION_TYPE>();
|
2021-11-26 16:05:05 +01:00
|
|
|
RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER);
|
|
|
|
UserRights ur = new UserRights(user.getUsername(), roleRights);
|
|
|
|
LOG.warn("Returning default user rights: " + ur);
|
2021-12-21 16:51:56 +01:00
|
|
|
gnaDEExtConfig.setUserRights(ur);
|
|
|
|
return gnaDEExtConfig;
|
2021-11-26 16:05:05 +01:00
|
|
|
}
|
2021-12-06 17:24:27 +01:00
|
|
|
}
|
2022-03-17 18:08:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the list use case descriptors.
|
|
|
|
*
|
|
|
|
* @param handlersIds the handlers ids
|
|
|
|
* @return the list use case descriptors
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-03-03 18:44:21 +01:00
|
|
|
@Override
|
2022-03-17 18:08:58 +01:00
|
|
|
public List<UseCaseDescriptorDV> getListUseCaseDescriptors(List<String> handlersIds) throws Exception {
|
|
|
|
LOG.info("getListUseCaseDescriptors called for handlersIds: " + handlersIds);
|
|
|
|
|
|
|
|
try {
|
|
|
|
List<UseCaseDescriptor> listUseCaseDescriptor = null;
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
try {
|
|
|
|
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
2022-05-20 12:31:58 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
if (handlersIds == null) {
|
|
|
|
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
|
|
|
|
LOG.info("handlersIds is null, so using default: " + handlersIds);
|
|
|
|
}
|
2022-08-11 12:07:07 +02:00
|
|
|
|
|
|
|
// TODO MUST BE USED THE FOLLOWING ONE
|
2022-05-20 12:31:58 +02:00
|
|
|
// listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
listUseCaseDescriptor = client.getList();
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error on contacting the Geoportal service";
|
2022-05-20 12:31:58 +02:00
|
|
|
LOG.error(error + " for handlers: " + handlersIds, e);
|
2022-03-17 18:08:58 +01:00
|
|
|
throw new Exception(
|
|
|
|
"Error when contacting the Geoportal service. Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listUseCaseDescriptor == null) {
|
|
|
|
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
|
|
|
|
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
|
|
|
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
|
|
|
}
|
|
|
|
|
2022-10-26 16:38:42 +02:00
|
|
|
LOG.info("for handlersIds {} returning {} " + UseCaseDescriptorDV.class.getSimpleName(), handlersIds,
|
2022-03-17 18:08:58 +01:00
|
|
|
listUCDDV.size());
|
|
|
|
return listUCDDV;
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on getting list of Use Case Descriptors", e);
|
|
|
|
throw new Exception("An error occurred when getting list of Use Case Descriptors", e);
|
|
|
|
}
|
2022-03-03 18:44:21 +01:00
|
|
|
}
|
2022-09-01 12:44:00 +02:00
|
|
|
|
2022-09-01 16:43:25 +02:00
|
|
|
/**
|
|
|
|
* Gets the lifecycle info for project id.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the lifecycle info for project id
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-09-01 12:44:00 +02:00
|
|
|
@Override
|
|
|
|
public LifecycleInformationDV getLifecycleInfoForProjectId(String profileID, String projectID) throws Exception {
|
2022-09-13 16:18:40 +02:00
|
|
|
LOG.info("getLifecycleInfoForProjectId called for profileID {}, projectID {} ", profileID, projectID);
|
2022-09-01 12:44:00 +02:00
|
|
|
|
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
try {
|
|
|
|
|
|
|
|
Project project = client.getProjectByID(profileID, projectID);
|
|
|
|
return ConvertToDataValueObjectModel.toLifecycleInformationDV(project.getLifecycleInformation());
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error on retrieving the LifecycleInfo for profileID " + profileID + " and projectID "
|
|
|
|
+ projectID;
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(error + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-09-13 16:18:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform action steps.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @param action the action
|
|
|
|
* @return the project DV
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public ProjectDV performActionSteps(String profileID, String projectID, ActionDefinitionDV action)
|
|
|
|
throws Exception {
|
|
|
|
LOG.info("performActionSteps called for profileID {}, projectID {}, action: " + action, profileID, projectID);
|
|
|
|
|
|
|
|
ProjectsCaller client = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
if (action == null || action.getCallSteps() == null || action.getCallSteps().length == 0) {
|
|
|
|
throw new Exception("Action called is invalid, no step defined");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Project project = null;
|
|
|
|
for (String stepID : action.getCallSteps()) {
|
|
|
|
LOG.info("calling stepID {} on projectID {}", stepID, projectID);
|
|
|
|
project = client.performStep(profileID, projectID, stepID, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
ProjectDV theProject = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
|
|
|
LOG.info("performActionSteps returning theProject with ID {}", projectID);
|
|
|
|
return theProject;
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on performing the workflow step/s on the project id " + projectID;
|
|
|
|
LOG.error(error, e);
|
2022-09-16 17:42:01 +02:00
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-03 17:52:16 +02:00
|
|
|
* Gets the relationships definition.
|
2022-09-16 17:42:01 +02:00
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
2022-10-03 17:52:16 +02:00
|
|
|
* @return the relationships definition
|
2022-09-16 17:42:01 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2022-10-03 17:52:16 +02:00
|
|
|
public List<RelationshipDefinitionDV> getRelationshipsDefinition(String profileID) throws Exception {
|
2022-09-16 17:42:01 +02:00
|
|
|
LOG.info("getRelationshipNames called for profileID {}", profileID);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2022-10-03 17:52:16 +02:00
|
|
|
List<RelationshipDefinitionDV> listRelDefinitionDV = SessionUtil
|
|
|
|
.getRelationshipsDefinition(getThreadLocalRequest(), profileID);
|
|
|
|
if (listRelDefinitionDV == null) {
|
2022-09-16 17:42:01 +02:00
|
|
|
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2022-10-03 17:52:16 +02:00
|
|
|
List<RelationshipDefinition> listRelDefinition = client.getRelationshipDefinitions(profileID);
|
|
|
|
if (listRelDefinition == null || listRelDefinition.isEmpty()) {
|
|
|
|
listRelDefinitionDV = new ArrayList<RelationshipDefinitionDV>(1);
|
|
|
|
} else {
|
|
|
|
listRelDefinitionDV = new ArrayList<RelationshipDefinitionDV>(listRelDefinition.size());
|
|
|
|
}
|
|
|
|
for (RelationshipDefinition relationshipDefinition : listRelDefinition) {
|
|
|
|
RelationshipDefinitionDV relDef = ConvertToDataValueObjectModel
|
|
|
|
.toRelationshipDefinition(relationshipDefinition);
|
|
|
|
listRelDefinitionDV.add(relDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
SessionUtil.setRelationshipDefinition(getThreadLocalRequest(), profileID, listRelDefinitionDV);
|
2022-09-16 17:42:01 +02:00
|
|
|
}
|
|
|
|
|
2022-10-03 17:52:16 +02:00
|
|
|
return listRelDefinitionDV;
|
2022-09-16 17:42:01 +02:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on reading the relations config from UCD " + profileID;
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
2022-09-13 16:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-09-21 10:52:56 +02:00
|
|
|
|
2022-10-03 17:52:16 +02:00
|
|
|
/**
|
|
|
|
* Creates the relationship.
|
|
|
|
*
|
|
|
|
* @param fromProfileID the from profile ID
|
|
|
|
* @param fromProjectID the from project ID
|
|
|
|
* @param relationshipId the relationship id
|
|
|
|
* @param toProfileID the to profile ID
|
|
|
|
* @param toProjectID the to project ID
|
|
|
|
* @return the relationship DV
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-09-21 10:52:56 +02:00
|
|
|
@Override
|
2022-10-03 17:52:16 +02:00
|
|
|
public void createRelationship(String fromProfileID, String fromProjectID, String relationshipId,
|
2022-09-21 10:52:56 +02:00
|
|
|
String toProfileID, String toProjectID) throws Exception {
|
|
|
|
LOG.info("createRelationship called");
|
|
|
|
|
|
|
|
try {
|
|
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
2022-10-03 17:52:16 +02:00
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
projects.createRelationship(fromProfileID, fromProjectID, relationshipId, toProfileID, toProjectID);
|
2022-09-21 10:52:56 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on creating the relationship";
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-05 14:45:27 +02:00
|
|
|
|
2022-11-17 11:53:11 +01:00
|
|
|
/**
|
|
|
|
* Delete relationship.
|
|
|
|
*
|
|
|
|
* @param fromProfileID the from profile ID
|
|
|
|
* @param fromProjectID the from project ID
|
|
|
|
* @param relationshipId the relationship id
|
|
|
|
* @param toProfileID the to profile ID
|
|
|
|
* @param toProjectID the to project ID
|
|
|
|
* @return the result document DV
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-10-05 14:45:27 +02:00
|
|
|
@Override
|
2022-10-06 11:25:31 +02:00
|
|
|
public ResultDocumentDV deleteRelationship(String fromProfileID, String fromProjectID, String relationshipId,
|
|
|
|
String toProfileID, String toProjectID) throws Exception {
|
2022-10-05 14:45:27 +02:00
|
|
|
LOG.info("deleteRelationship called");
|
|
|
|
try {
|
|
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
projects.deleteRelationship(fromProfileID, fromProjectID, relationshipId, toProfileID, toProjectID);
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
return getResultDocumentFoProjectByID(fromProfileID, fromProjectID);
|
2022-10-06 11:25:31 +02:00
|
|
|
|
2022-10-05 14:45:27 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on deleting the relationship";
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
}
|
2022-09-21 17:20:09 +02:00
|
|
|
|
2022-10-03 17:52:16 +02:00
|
|
|
/**
|
|
|
|
* Gets the project by ID.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the project by ID
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-09-21 17:20:09 +02:00
|
|
|
@Override
|
|
|
|
public ProjectDV getProjectByID(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("getProjectByID called");
|
|
|
|
|
|
|
|
try {
|
|
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
2022-10-03 17:52:16 +02:00
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2022-09-21 17:20:09 +02:00
|
|
|
Project project = projects.getProjectByID(profileID, projectID);
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
|
|
|
LOG.info("returning: " + projectDV.getId());
|
|
|
|
return projectDV;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on reading the project with id: " + projectID;
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-03 17:52:16 +02:00
|
|
|
/**
|
|
|
|
* Gets the result document fo project by ID.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the result document fo project by ID
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-09-21 17:20:09 +02:00
|
|
|
@Override
|
|
|
|
public ResultDocumentDV getResultDocumentFoProjectByID(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("getResultDocumentFoProjectByID called");
|
|
|
|
|
|
|
|
try {
|
2022-10-03 17:52:16 +02:00
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
2022-11-17 11:53:11 +01:00
|
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
2022-09-21 17:20:09 +02:00
|
|
|
Project project = projects.getProjectByID(profileID, projectID);
|
|
|
|
ResultDocumentDV documentDV = ConvertToDataValueObjectModel.toResultDocumentDV(project);
|
|
|
|
LOG.info("returning: " + documentDV.getId());
|
|
|
|
return documentDV;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error occurred on reading the project with id: " + projectID;
|
|
|
|
LOG.error(error, e);
|
|
|
|
throw new Exception(
|
|
|
|
error + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-05 14:45:27 +02:00
|
|
|
|
2022-11-17 11:53:11 +01:00
|
|
|
/**
|
|
|
|
* Temporal reference for project.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the temporal reference DV
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public TemporalReferenceDV temporalReferenceForProject(String profileID, String projectID) {
|
|
|
|
LOG.info("temporalReferenceForProject called for profileID: {}, and projectID: {}", profileID, projectID);
|
|
|
|
String template = null;
|
|
|
|
|
|
|
|
if (profileID == null || projectID == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
|
|
|
Project theProject = projects.getProjectByID(profileID, projectID);
|
|
|
|
|
|
|
|
template = SessionUtil.getJSONTimelineTemplate(this.getThreadLocalRequest(), profileID);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (template == null) {
|
|
|
|
|
|
|
|
Document temporalJsonTemplate = GeoportalClientCaller.useCaseDescriptors()
|
|
|
|
.readTemporalDimensionTemplate(theProject.getProfileID());
|
|
|
|
|
|
|
|
if (temporalJsonTemplate != null) {
|
|
|
|
template = new Document(temporalJsonTemplate).toJson();
|
|
|
|
LOG.info(UseCaseDescriptorCaller.TIMELINE_CONFIG_TJT_DOCUMENT + " read is: " + template);
|
|
|
|
SessionUtil.setJSONTimelineTemplate(this.getThreadLocalRequest(), theProject.getProfileID(),
|
|
|
|
template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.warn(GEOPORTAL_DATA_HANDLER.geoportal_timeline_json_template.getType()
|
|
|
|
+ " not found!!! Timeline cannot be available");
|
|
|
|
}
|
|
|
|
|
|
|
|
// String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\","
|
|
|
|
// + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}";
|
|
|
|
|
|
|
|
if (template != null) {
|
|
|
|
|
|
|
|
JSONObject sourceJsonTemplate = new JSONObject(template);
|
|
|
|
JSONObject targetJsonObject = ConvertToDataValueObjectModel.toTimelineJSONModel(theProject,
|
|
|
|
sourceJsonTemplate, theProject.getProfileID(), theProject.getId(), null);
|
|
|
|
|
|
|
|
return ConvertToDataValueObjectModel.toTemporalReferenceDV(theProject, targetJsonObject);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
String erroMsg = "Error occurred on reading temporalReference for id: " + projectID;
|
|
|
|
LOG.warn(erroMsg, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
/**
|
|
|
|
* Gets the project edit.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the project edit
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-12-07 09:43:48 +01:00
|
|
|
@Override
|
|
|
|
public ProjectEdit getProjectEdit(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("getProjectEdit called for profileID: {}, and projectID: {}", profileID, projectID);
|
|
|
|
try {
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
GCubeUser user = pContext.getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
String scope = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
ProjectsCaller clientProjects = GeoportalClientCaller.projects();
|
|
|
|
Project theProject = clientProjects.getProjectByID(profileID, projectID);
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
projectBuilder.relationships(true);
|
|
|
|
ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder);
|
|
|
|
|
|
|
|
ProjectEdit projectEdit = Geoportal_JSON_Mapper.loadProjectEdit(theProjectDV, scope, user.getUsername());
|
2023-04-17 16:03:40 +02:00
|
|
|
|
2022-12-07 09:43:48 +01:00
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectEdit);
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
LOG.info(ProjectEdit.class.getSimpleName() + " returing not null: " + (projectEdit != null));
|
2022-12-07 09:43:48 +01:00
|
|
|
return projectEdit;
|
|
|
|
} catch (Exception e) {
|
2023-05-02 15:16:59 +02:00
|
|
|
String erroMsg = "Error occurred on reading " + ProjectEdit.class.getSimpleName() + " DTO for id: "
|
|
|
|
+ projectID;
|
2023-04-27 16:39:21 +02:00
|
|
|
LOG.warn(erroMsg, e);
|
|
|
|
throw new Exception(
|
|
|
|
erroMsg + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
}
|
2023-05-02 15:16:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the project view.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @param projectID the project ID
|
|
|
|
* @return the project view
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2023-04-27 16:39:21 +02:00
|
|
|
@Override
|
|
|
|
public ProjectView getProjectView(String profileID, String projectID) throws Exception {
|
|
|
|
LOG.info("getProjectEdit called for profileID: {}, and projectID: {}", profileID, projectID);
|
|
|
|
try {
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
GCubeUser user = pContext.getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
String scope = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
ProjectsCaller clientProjects = GeoportalClientCaller.projects();
|
|
|
|
Project theProject = clientProjects.getProjectByID(profileID, projectID);
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
projectBuilder.relationships(true);
|
|
|
|
ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder);
|
|
|
|
|
|
|
|
ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, scope, user.getUsername());
|
|
|
|
|
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:16:59 +02:00
|
|
|
LOG.info(ProjectView.class.getSimpleName() + " returing not null: " + (projectView != null));
|
2023-04-27 16:39:21 +02:00
|
|
|
return projectView;
|
|
|
|
} catch (Exception e) {
|
2023-05-02 15:16:59 +02:00
|
|
|
String erroMsg = "Error occurred on reading " + ProjectView.class.getSimpleName() + " DTO for id: "
|
|
|
|
+ projectID;
|
2022-12-07 09:43:48 +01:00
|
|
|
LOG.warn(erroMsg, e);
|
|
|
|
throw new Exception(
|
|
|
|
erroMsg + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
}
|
|
|
|
}
|
2023-04-17 16:03:40 +02:00
|
|
|
|
2022-11-09 15:12:42 +01:00
|
|
|
/**
|
|
|
|
* Pretty print client data entry map.
|
|
|
|
*
|
|
|
|
* @param toMap the to map
|
|
|
|
*/
|
|
|
|
private void prettyPrintClientDataEntryMap(HashMap<ProjectFormCard, List<GeoNaFormDataObject>> toMap) {
|
|
|
|
|
|
|
|
for (ProjectFormCard theType : toMap.keySet()) {
|
|
|
|
LOG.debug("\n\n");
|
|
|
|
LOG.debug(theType.toString());
|
|
|
|
List<GeoNaFormDataObject> list = toMap.get(theType);
|
|
|
|
for (GeoNaFormDataObject geoNaFormDataObject : list) {
|
|
|
|
LOG.debug("\t has " + geoNaFormDataObject.getListGDB().size() + " data bean/s");
|
|
|
|
int i = 0;
|
|
|
|
for (GenericDatasetBean gbd : geoNaFormDataObject.getListGDB()) {
|
|
|
|
LOG.debug("\t " + ++i + ") " + GenericDatasetBean.class.getSimpleName() + " entries:");
|
|
|
|
Map<String, List<String>> map = gbd.getFormDataEntryFields();
|
|
|
|
for (String keyEntry : map.keySet()) {
|
|
|
|
LOG.debug("\t " + keyEntry + ": " + map.get(keyEntry));
|
|
|
|
}
|
2023-03-17 12:41:56 +01:00
|
|
|
// for (FileUploaded fup : gbd.getFilesUploaded()) {
|
|
|
|
// LOG.debug("\t " + fup);
|
|
|
|
// }
|
2022-11-09 15:12:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 17:04:13 +02:00
|
|
|
}
|