2020-10-07 17:04:13 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
import java.io.File;
|
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;
|
2020-10-20 09:58:56 +02:00
|
|
|
import java.util.List;
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.util.Map;
|
2020-10-20 09:58:56 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2022-05-20 12:31:58 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
2021-07-23 17:40:50 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
2021-09-02 18:14:49 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
|
2022-03-03 18:44:21 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.TempFile;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
2021-07-23 17:40:50 +02:00
|
|
|
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
2021-08-04 17:11:46 +02:00
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
2020-12-01 18:15:13 +01:00
|
|
|
import org.gcube.application.geoportalcommon.GeoportalCommon;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
|
|
|
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;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
|
2020-12-01 18:15:13 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
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.ACTION_ON_ITEM;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
|
|
|
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-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
|
2022-05-20 12:31:58 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.LifecycleInformationDV;
|
2022-03-17 18:08:58 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
|
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;
|
2021-08-04 17:11:46 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
2021-10-05 19:17:05 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
|
2021-09-29 11:38:24 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
|
2021-11-26 16:05:05 +01:00
|
|
|
import org.gcube.common.portal.PortalContext;
|
2021-08-05 16:49:04 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
|
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;
|
2020-10-21 16:52:07 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
2021-12-21 16:51:56 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
|
2020-10-20 09:58:56 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
2020-10-21 15:36:50 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
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;
|
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
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-05-20 12:31:58 +02:00
|
|
|
* @param profileID the profile ID
|
2020-12-01 18:15:13 +01:00
|
|
|
* @param listGeonaFormObjects the list geona form objects
|
|
|
|
* @return the commit report
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-10-20 11:49:23 +02:00
|
|
|
@Override
|
2022-05-20 12:31:58 +02:00
|
|
|
public CommitReport saveGeonaDataForms(String profileID, List<GeoNaFormDataObject> listGeonaFormObjects)
|
|
|
|
throws Exception {
|
|
|
|
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();
|
|
|
|
JSONObject theDocument = metadataConverter.convert(listGeonaFormObjects);
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-03-17 18:08:58 +01:00
|
|
|
// Uploading files
|
|
|
|
LOG.debug("Going to upload the files");
|
|
|
|
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
|
2022-03-07 17:48:32 +01:00
|
|
|
List<GenericDatasetBean> listGDB = geoNaFormDataObject.getListGDB();
|
|
|
|
GcubeProfileDV profile = geoNaFormDataObject.getGcubeProfileDV();
|
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
LOG.info("The profile is: " + profile);
|
2022-03-07 17:48:32 +01:00
|
|
|
for (GenericDatasetBean gdb : listGDB) {
|
2022-03-17 18:08:58 +01:00
|
|
|
List<FileUploaded> files = gdb.getFilesUploaded();
|
2022-05-20 12:31:58 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
if (files.size() > 0) {
|
2022-05-20 12:31:58 +02:00
|
|
|
String parentPath = profile.getParentName();
|
|
|
|
LOG.info("Uploading file/s in the parentPath: " + parentPath);
|
2022-03-17 18:08:58 +01:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
FileUploaded file = files.get(i);
|
2022-05-20 12:31:58 +02:00
|
|
|
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-03-17 18:08:58 +01:00
|
|
|
}
|
2022-05-20 12:31:58 +02:00
|
|
|
|
|
|
|
mongoService.registerFileSet(profileID, theProject, new File(file.getTempSystemPath()),
|
|
|
|
parentPath, filePath.getFieldName(), filePath.getFieldDefinition());
|
|
|
|
|
2022-03-07 17:48:32 +01:00
|
|
|
}
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
}
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2021-01-27 10:43:57 +01:00
|
|
|
}
|
2020-10-21 16:16:53 +02:00
|
|
|
}
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2022-05-20 12:31:58 +02:00
|
|
|
LifecycleInformation lifecycleInfo = theProject.getLifecycleInformation();
|
|
|
|
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lifecycleInfo);
|
|
|
|
return new CommitReport(theProject.getId(), liDV);
|
2021-08-02 12:52:30 +02:00
|
|
|
|
2020-12-01 18:15:13 +01:00
|
|
|
} catch (Exception e) {
|
2022-05-20 12:31:58 +02:00
|
|
|
LOG.error("Error on uploading files: ", e);
|
2020-12-01 18:15:13 +01:00
|
|
|
throw new Exception(
|
2022-05-20 12:31:58 +02:00
|
|
|
"Error occurred on uploading files, try again or contact the support. Error: " + e.getMessage());
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
2020-10-30 15:37:08 +01:00
|
|
|
|
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
|
|
|
|
public GeonaISConfig getGeonaInitConfig() {
|
|
|
|
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
|
|
|
|
2020-10-21 15:36:50 +02:00
|
|
|
GeonaISConfig configs = new GeonaISConfig(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.
|
|
|
|
*
|
2021-07-30 11:53:12 +02:00
|
|
|
* @param itemId the item id is the mongoId
|
2020-12-01 18:15:13 +01:00
|
|
|
* @param recordType the record type
|
|
|
|
* @return the links for
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2022-05-20 12:31:58 +02:00
|
|
|
public GeoNaItemRef getLinksFor(String itemId, String profileID) throws Exception {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.info("getLinksFor called");
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
2021-12-21 16:51:56 +01:00
|
|
|
GNADataViewerConfigProfile grViewerProfile = SessionUtil
|
|
|
|
.getGeportalViewerResourceProfile(getThreadLocalRequest());
|
2021-08-05 16:49:04 +02:00
|
|
|
GeoportalCommon gc = new GeoportalCommon(grViewerProfile);
|
2022-05-20 12:31:58 +02:00
|
|
|
GeoNaItemRef item = new GeoNaItemRef(itemId, profileID);
|
2021-09-14 13:08:55 +02:00
|
|
|
item = gc.getPublicLinksFor(item, false);
|
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
|
|
|
*
|
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-03-17 18:08:58 +01:00
|
|
|
List<ProjectDV> listProjectDV = SessionUtil.getListOfProjectsForProfileID(getThreadLocalRequest(),
|
|
|
|
theProfileID);
|
|
|
|
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
|
|
|
|
if (reloadFromService || listProjectDV == null) {
|
|
|
|
List<Project> listProject = client.getListForProfileID(theProfileID);
|
|
|
|
|
|
|
|
listProjectDV = new ArrayList<ProjectDV>(listProject.size());
|
|
|
|
for (Project project : listProject) {
|
|
|
|
listProjectDV.add(ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder));
|
|
|
|
}
|
|
|
|
SessionUtil.setListOfProjectsForProfileID(getThreadLocalRequest(), theProfileID, listProjectDV);
|
|
|
|
}
|
|
|
|
|
|
|
|
int listConcessioniSize = listProjectDV.size();
|
|
|
|
|
|
|
|
ResultSetPaginatedData searchedData = client.queryOnMongo(theProfileID, listConcessioniSize, start, limit,
|
|
|
|
filter, projectBuilder);
|
|
|
|
|
|
|
|
// public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit,
|
|
|
|
// SearchingFilter filter, String recordType, ProjectDVBuilder projectDVBuilder) throws Exception {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
* MongoServiceCommon serviceCommon = new MongoServiceCommon();
|
|
|
|
*
|
|
|
|
* // TODO MUST BE REPLACED BY COUNT List<Concessione> listOfConcessioni =
|
|
|
|
* SessionUtil.getListOfConcessioni(getThreadLocalRequest(), reloadFromService);
|
|
|
|
* int listConcessioniSize = listOfConcessioni.size();
|
|
|
|
*
|
|
|
|
* ResultSetPaginatedData searchedData =
|
|
|
|
* serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
|
|
|
|
* "concessione"); return searchedData;
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
LOG.debug("returning {}", searchedData.getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ProjectDV> data = searchedData.getData();
|
|
|
|
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);
|
2021-08-02 12:52:30 +02:00
|
|
|
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
|
|
|
|
}
|
2021-07-23 17:40:50 +02:00
|
|
|
|
2021-08-02 12:52:30 +02:00
|
|
|
}
|
2020-12-01 18:15:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pretty print client data entry map.
|
|
|
|
*
|
|
|
|
* @param toMap the to map
|
|
|
|
*/
|
2022-03-04 16:44:51 +01:00
|
|
|
private void prettyPrintClientDataEntryMap(HashMap<ProjectFormCard, List<GeoNaFormDataObject>> toMap) {
|
2020-12-01 18:15:13 +01:00
|
|
|
|
2022-03-04 16:44:51 +01:00
|
|
|
for (ProjectFormCard theType : toMap.keySet()) {
|
2020-10-20 15:25:26 +02:00
|
|
|
LOG.debug("\n\n");
|
|
|
|
LOG.debug(theType.toString());
|
2020-10-20 11:49:23 +02:00
|
|
|
List<GeoNaFormDataObject> list = toMap.get(theType);
|
|
|
|
for (GeoNaFormDataObject geoNaFormDataObject : list) {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.debug("\t has " + geoNaFormDataObject.getListGDB().size() + " data bean/s");
|
2020-10-20 11:49:23 +02:00
|
|
|
int i = 0;
|
|
|
|
for (GenericDatasetBean gbd : geoNaFormDataObject.getListGDB()) {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.debug("\t " + ++i + ") " + GenericDatasetBean.class.getSimpleName() + " entries:");
|
2020-10-20 11:49:23 +02:00
|
|
|
Map<String, List<String>> map = gbd.getFormDataEntryFields();
|
|
|
|
for (String keyEntry : map.keySet()) {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.debug("\t " + keyEntry + ": " + map.get(keyEntry));
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
|
|
|
for (FileUploaded fup : gbd.getFilesUploaded()) {
|
2020-12-01 18:15:13 +01:00
|
|
|
LOG.debug("\t " + fup);
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-05 16:49:04 +02:00
|
|
|
|
2021-09-16 12:15:07 +02:00
|
|
|
/**
|
|
|
|
* Delete record.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param recordType the record type
|
|
|
|
* @return true, if successful
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-08-05 16:49:04 +02:00
|
|
|
@Override
|
|
|
|
public boolean deleteRecord(String itemId, RECORD_TYPE recordType) throws Exception {
|
2021-09-16 12:15:07 +02:00
|
|
|
LOG.info("deleteRecord called with itemId: " + itemId + ", recordType: " + recordType);
|
2021-08-05 16:49:04 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Item id is null");
|
|
|
|
|
|
|
|
if (recordType.equals(RECORD_TYPE.CONCESSIONE)) {
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
2021-09-16 12:15:07 +02:00
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
2021-08-05 16:49:04 +02:00
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
clientMongo.deleteById(itemId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on deleting the project with item id: " + itemId, e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on deleting the project with id: " + itemId + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2021-09-16 12:15:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update record.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param jsonUpdate the json update
|
|
|
|
* @param recordType the record type
|
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
|
2021-09-22 11:38:52 +02:00
|
|
|
public ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception {
|
2021-09-16 12:15:07 +02:00
|
|
|
LOG.info("updateRecord called with itemId: " + itemId + ", recordType: " + recordType);
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Item id is null");
|
|
|
|
|
|
|
|
LOG.debug("jsonUpdate is: " + jsonUpdate);
|
|
|
|
if (recordType.equals(RECORD_TYPE.CONCESSIONE)) {
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
Concessione concessione = clientMongo.update(itemId, jsonUpdate);
|
2021-09-24 12:06:53 +02:00
|
|
|
LOG.debug("Got Record updated: " + concessione);
|
2021-09-22 11:38:52 +02:00
|
|
|
ConcessioneDV concessionDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
|
2021-09-24 12:06:53 +02:00
|
|
|
LOG.info("Record with id " + concessionDV.getItemId() + "updated correclty");
|
2021-09-22 11:38:52 +02:00
|
|
|
return concessionDV;
|
2021-09-16 12:15:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on updating the project with item id: " + itemId, e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the JSON record.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param recordType the record type
|
2021-09-24 12:06:53 +02:00
|
|
|
* @return the JSON record representing the itemId
|
2021-09-16 12:15:07 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getJSONRecord(String itemId, RECORD_TYPE recordType) throws Exception {
|
|
|
|
LOG.info("getJSONRecord called with itemId: " + itemId + ", recordType: " + recordType);
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Item id is null");
|
|
|
|
|
|
|
|
if (recordType.equals(RECORD_TYPE.CONCESSIONE)) {
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
Concessione concessione = clientMongo.getById(itemId);
|
|
|
|
return serviceUtil.toJSON(concessione);
|
|
|
|
}
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2021-09-16 12:15:07 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on reading the JSON project with item id: " + itemId, e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on reading the JSON project with id: " + itemId + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2021-09-27 18:32:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the record.
|
|
|
|
*
|
2021-10-05 19:17:05 +02:00
|
|
|
* @param itemId the item id
|
2021-09-27 18:32:19 +02:00
|
|
|
* @param recordType the record type
|
|
|
|
* @return the record
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public ConcessioneDV getRecord(String itemId, RECORD_TYPE recordType) throws Exception {
|
|
|
|
LOG.info("getRecord called with itemId: " + itemId + ", recordType: " + recordType);
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Item id is null");
|
|
|
|
|
|
|
|
if (recordType.equals(RECORD_TYPE.CONCESSIONE)) {
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
Concessione concessione = clientMongo.getById(itemId);
|
|
|
|
return ConvertToDataViewModel.toConcessione(concessione);
|
|
|
|
}
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2021-09-27 18:32:19 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on reading the record with item id: " + itemId, e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on reading the record with id: " + itemId + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read file set paths.
|
|
|
|
*
|
|
|
|
* @return the list
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2021-09-29 11:38:24 +02:00
|
|
|
public FileSetPathsDV readFileSetPaths() throws Exception {
|
2021-09-27 18:32:19 +02:00
|
|
|
LOG.info("readFileSetPaths called");
|
2021-09-29 11:38:24 +02:00
|
|
|
return ConvertToDataViewModel.getFileSetPaths();
|
2021-09-27 18:32:19 +02:00
|
|
|
|
|
|
|
}
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2021-09-29 18:27:22 +02:00
|
|
|
/**
|
|
|
|
* Update record.
|
|
|
|
*
|
2021-10-05 19:17:05 +02:00
|
|
|
* @param itemId the item id
|
|
|
|
* @param recordType the record type
|
|
|
|
* @param section the section
|
|
|
|
* @param pathIndex the path index
|
|
|
|
* @param keepCurrentContent the keep current content
|
|
|
|
* @param gDBean the g D bean
|
2021-09-29 18:27:22 +02:00
|
|
|
* @return the updated JSON string representing the itemId
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2021-10-05 19:17:05 +02:00
|
|
|
public ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex,
|
|
|
|
List<WorkspaceContentDV> keepCurrentContent, GenericDatasetBean gDBean) throws Exception {
|
|
|
|
LOG.info("updateSectionForRecord called with itemId: " + itemId + ", section: " + section + ", pathIndex: "
|
|
|
|
+ pathIndex + ", gDBean: " + gDBean, "");
|
2021-09-29 18:27:22 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Item id is null");
|
|
|
|
|
2021-10-05 19:17:05 +02:00
|
|
|
if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) {
|
2021-09-29 18:27:22 +02:00
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2021-09-29 18:27:22 +02:00
|
|
|
String toEditPath = null;
|
|
|
|
AddSectionToConcessioneRequest request = null;
|
2021-10-05 19:17:05 +02:00
|
|
|
List<TempFile> files = new ArrayList<TempFile>();
|
2021-11-26 16:05:05 +01:00
|
|
|
|
2021-10-05 19:17:05 +02:00
|
|
|
// Managing files already present as current content and kept by user
|
|
|
|
List<TempFile> keepFiles = serviceUtil.toTemFilesFromWSC(keepCurrentContent);
|
|
|
|
if (keepFiles != null) {
|
|
|
|
files.addAll(keepFiles);
|
2021-11-26 16:05:05 +01:00
|
|
|
LOG.debug(keepFiles.size() + " current corrent file/s has/have been added to list of files");
|
2021-10-05 19:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Managing new files uploaded by user
|
|
|
|
List<TempFile> newFiles = serviceUtil.toTemFiles(gDBean.getFilesUploaded());
|
|
|
|
if (newFiles != null) {
|
|
|
|
files.addAll(newFiles);
|
2021-11-26 16:05:05 +01:00
|
|
|
LOG.debug(newFiles.size() + " new file/s has/have been added to list of files");
|
2021-10-05 19:17:05 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
// TODO MUST BE REVISITED
|
2021-10-05 19:17:05 +02:00
|
|
|
|
2022-03-17 18:08:58 +01:00
|
|
|
/*
|
|
|
|
* if (section.contains("abstract_relazione")) {
|
|
|
|
*
|
|
|
|
* toEditPath = Paths.ABSTRACT_RELAZIONE; request = new
|
|
|
|
* AddSectionToConcessioneRequest(toEditPath, files);
|
|
|
|
*
|
|
|
|
* } else if (section.contains("immagini")) { toEditPath =
|
|
|
|
* Paths.imgByIndex(pathIndex); request = new
|
|
|
|
* AddSectionToConcessioneRequest(toEditPath, files);
|
|
|
|
*
|
|
|
|
* } else if (section.contains("relazione")) { toEditPath = Paths.RELAZIONE;
|
|
|
|
* request = new AddSectionToConcessioneRequest(toEditPath, files);
|
|
|
|
*
|
|
|
|
* } else if (section.contains("posizionamentoScavo")) { toEditPath =
|
|
|
|
* Paths.POSIZIONAMENTO; request = new
|
|
|
|
* AddSectionToConcessioneRequest(toEditPath, files);
|
|
|
|
*
|
|
|
|
* } else if (section.contains("piante")) { toEditPath =
|
|
|
|
* Paths.piantaByIndex(pathIndex); request = new
|
|
|
|
* AddSectionToConcessioneRequest(toEditPath, files); }
|
|
|
|
*
|
|
|
|
*/
|
2021-09-29 18:27:22 +02:00
|
|
|
|
2021-10-05 19:17:05 +02:00
|
|
|
// Unpublish
|
|
|
|
LOG.info("Unpublishing " + itemId);
|
|
|
|
clientMongo.unPublish(itemId);
|
|
|
|
|
|
|
|
// update Fileset
|
|
|
|
LOG.info("Removing old fileset.. ");
|
|
|
|
Concessione concessione = clientMongo.cleanFileSet(itemId, toEditPath);
|
|
|
|
|
|
|
|
LOG.debug("Sending new Fileset ..");
|
2021-11-26 16:05:05 +01:00
|
|
|
if (files.size() > 0) {
|
2021-10-05 19:17:05 +02:00
|
|
|
// StorageUtils storage=new StorageUtils();
|
|
|
|
// Building TempFile
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
2021-11-26 16:05:05 +01:00
|
|
|
LOG.info("Registering FileSet into recordId " + itemId + " with request path: " + toEditPath
|
|
|
|
+ " and: " + files.size() + " file/s");
|
2021-10-05 19:17:05 +02:00
|
|
|
concessione = clientMongo.registerFileSet(itemId, request);
|
2021-11-26 16:05:05 +01:00
|
|
|
} else {
|
2021-10-05 19:17:05 +02:00
|
|
|
LOG.info("Fileset is empty, skipping registerFileSet");
|
|
|
|
}
|
2021-11-26 16:05:05 +01:00
|
|
|
|
|
|
|
LOG.info("Publishings itemId: " + itemId);
|
2021-09-29 18:27:22 +02:00
|
|
|
concessione = clientMongo.publish(itemId);
|
2021-11-26 16:05:05 +01:00
|
|
|
|
|
|
|
LOG.debug("returning concessione: " + concessione);
|
2021-10-05 19:17:05 +02:00
|
|
|
return ConvertToDataViewModel.toConcessione(concessione);
|
2021-09-29 18:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error on updating the project with item id: " + itemId, e);
|
|
|
|
throw new Exception(
|
|
|
|
"Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
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
|
2021-12-21 16:51:56 +01:00
|
|
|
public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception {
|
|
|
|
LOG.info("readDataViewerConfig called");
|
2021-11-26 16:05:05 +01:00
|
|
|
|
|
|
|
GCubeUser user = null;
|
2021-12-21 16:51:56 +01:00
|
|
|
GNADataEntryExtConfigProfile gnaDEExtConfig = new GNADataEntryExtConfigProfile();
|
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.setListItemFields(config.getListItemFields());
|
|
|
|
gnaDEExtConfig.setPermissionsForRole(listUserRightsForRole);
|
|
|
|
|
2021-11-26 16:05:05 +01:00
|
|
|
// DEV MODE
|
|
|
|
if (!SessionUtil.isIntoPortal()) {
|
|
|
|
LOG.warn("OUT OF PORTAL - DEV MODE detected");
|
2021-12-21 16:51:56 +01:00
|
|
|
GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR;
|
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);
|
|
|
|
|
|
|
|
Map<ACTION_ON_ITEM, OPERATION_TYPE> permissions = new HashMap<ACTION_ON_ITEM, RoleRights.OPERATION_TYPE>();
|
|
|
|
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
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public List<DocumentConfigDV> getListDocumentConfigurationForId(String id) throws Exception {
|
|
|
|
//// MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
|
|
|
|
//// return mock.getListDocumentConfig();
|
|
|
|
//
|
|
|
|
// UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
//
|
|
|
|
// //TODO ID MUST BE THE HANDLER ID
|
|
|
|
// List<UseCaseDescriptor> useCaseDescriptor;
|
|
|
|
// try {
|
|
|
|
// List<String> handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId());
|
|
|
|
// useCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
|
|
|
// } catch (Exception e1) {
|
|
|
|
// throw new Exception("Error when contacting the Geoportal service. Refresh and try again or contact the support");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// List<UseCaseDescriptorDV> listUCD = new ArrayList<UseCaseDescriptorDV>(useCaseDescriptor.size());
|
|
|
|
// for (UseCaseDescriptor ucd : useCaseDescriptor) {
|
|
|
|
// listUCD.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// List<DocumentConfigDV> listDocumentConfig = new ArrayList<DocumentConfigDV>();
|
|
|
|
//
|
|
|
|
// for (UseCaseDescriptorDV useCaseDescriptorDV : listUCD) {
|
|
|
|
// DocumentConfigDV documentConfigDV = new DocumentConfigDV();
|
|
|
|
// documentConfigDV.setId(useCaseDescriptorDV.getId());
|
|
|
|
// documentConfigDV.setType(useCaseDescriptorDV.getName());
|
|
|
|
// documentConfigDV.setItemType(useCaseDescriptorDV.getName());
|
|
|
|
// ConfigHandlerDV config = new ConfigHandlerDV();
|
|
|
|
// List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers();
|
|
|
|
// List<GcubeProfileDV> gcubeProfiles = new ArrayList<GcubeProfileDV>();
|
|
|
|
// for (HandlerDeclarationDV handler : handlers) {
|
|
|
|
// ConfigurationDV<?> docConfig = handler.getConfiguration();
|
|
|
|
// try {
|
|
|
|
// List<GcubeProfileDV> theConfig = (List<GcubeProfileDV>) docConfig.getConfiguration();
|
|
|
|
// if(theConfig!=null) {
|
|
|
|
// gcubeProfiles.addAll(gcubeProfiles);
|
|
|
|
// }
|
|
|
|
// }catch (Exception e) {
|
|
|
|
// LOG.warn("The configuration read for "+documentConfigDV.getId()+ " is not a List of "+GcubeProfileDV.class.getSimpleName()+", skipping it");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(gcubeProfiles.size()>0) {
|
|
|
|
// config.setGcubeProfiles(gcubeProfiles);
|
|
|
|
// documentConfigDV.setConfiguration(config);
|
|
|
|
// listDocumentConfig.add(documentConfigDV);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return listDocumentConfig;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-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));
|
|
|
|
}
|
|
|
|
|
|
|
|
// MOCK
|
|
|
|
/*
|
|
|
|
* List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>();
|
|
|
|
* UseCaseDescriptorDV usecaseDescriptorDV = new UseCaseDescriptorDV("theId",
|
|
|
|
* "version", "listConcessioni", null); List<HandlerDeclarationDV> handlers =
|
|
|
|
* new ArrayList<HandlerDeclarationDV>();
|
|
|
|
*
|
|
|
|
* List<GcubeProfileDV> gcubeProfiles = new ArrayList<GcubeProfileDV>();
|
|
|
|
* GcubeProfileDV profile = new GcubeProfileDV();
|
|
|
|
* profile.setGcubeName("GcubeName");
|
|
|
|
* profile.setGcubeSecondaryType("GcubeSecondaryType");
|
|
|
|
* gcubeProfiles.add(profile);
|
|
|
|
*
|
|
|
|
* ConfigurationDV<List<GcubeProfileDV>> configuration = new
|
|
|
|
* ConfigurationDV<List<GcubeProfileDV>>(gcubeProfiles); HandlerDeclarationDV
|
|
|
|
* handler = new
|
|
|
|
* HandlerDeclarationDV(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(),
|
|
|
|
* GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getType(), "Concessioni",
|
|
|
|
* configuration, GEOPORTAL_DATA_HANDLER.geoportal_data_entry);
|
|
|
|
*
|
|
|
|
* handlers.add(handler); usecaseDescriptorDV.setHandlers(handlers);
|
|
|
|
* listUCDDV.add(usecaseDescriptorDV);
|
|
|
|
*/
|
|
|
|
|
|
|
|
LOG.info("for handlersIds {} returning {} " + UseCaseDescriptor.class.getSimpleName(), handlersIds,
|
|
|
|
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
|
|
|
}
|
2020-10-07 17:04:13 +02:00
|
|
|
}
|