diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 3b554c5..2020d09 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -1469,4 +1469,14 @@ public interface TDGWTService extends RemoteService { public String startGeometryCreatePoint(GeometryCreatePointSession geometryCreatePointSession) throws TDGWTServiceException; + /** + * Retrieve the URL of default SDMX Registry + * + * + * @return URL of the default SDMX Registry + * @throws TDGWTServiceException + * Exception + */ + public String getDefaultSDMXRegistryURL() throws TDGWTServiceException; + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 6be95ee..cc6dd0d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -97,8 +97,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; public interface TDGWTServiceAsync { - public static TDGWTServiceAsync INSTANCE = (TDGWTServiceAsync) GWT - .create(TDGWTService.class); + public static TDGWTServiceAsync INSTANCE = (TDGWTServiceAsync) GWT.create(TDGWTService.class); void hello(AsyncCallback callback); @@ -108,21 +107,18 @@ public interface TDGWTServiceAsync { void restoreUISession(TRId startTRId, AsyncCallback callback); - void getUriFromResolver(UriResolverSession uriResolverSession, - AsyncCallback callback); + void getUriFromResolver(UriResolverSession uriResolverSession, AsyncCallback callback); void getVREFolderIdByScope(AsyncCallback callback); // PeriodDataType void getPeriodDataTypes(AsyncCallback> callback); - void getHierarchicalRelationshipForPeriodDataTypes( - PeriodDataType periodDataType, + void getHierarchicalRelationshipForPeriodDataTypes(PeriodDataType periodDataType, AsyncCallback> callback); // ValueDataFormat - void getValueDataFormatsMap( - AsyncCallback>> callback); + void getValueDataFormatsMap(AsyncCallback>> callback); void getValueDataFormatsOfColumnDataType(ColumnDataType columnDataType, AsyncCallback> callback); @@ -130,8 +126,7 @@ public interface TDGWTServiceAsync { // TabularResource void getCurrentTRId(AsyncCallback callback); - void createTabularResource(TabResource tabResource, - AsyncCallback callback); + void createTabularResource(TabResource tabResource, AsyncCallback callback); void removeTabularResource(TRId trId, AsyncCallback callback); @@ -141,11 +136,9 @@ public interface TDGWTServiceAsync { void getTabResourceInformation(AsyncCallback callback); - void getTabResourceInformation(TRId trId, - AsyncCallback callback); + void getTabResourceInformation(TRId trId, AsyncCallback callback); - void setTabResourceInformation(TabResource tabResource, - AsyncCallback callback); + void setTabResourceInformation(TabResource tabResource, AsyncCallback callback); void setTabResourceToFinal(TRId trId, AsyncCallback callback); @@ -155,103 +148,83 @@ public interface TDGWTServiceAsync { void getTabularResources(AsyncCallback> callback); - void getTabularResourcesAndLastTables( - AsyncCallback> callback); + void getTabularResourcesAndLastTables(AsyncCallback> callback); void getLastTable(TRId trId, AsyncCallback callback); void getTable(TRId trId, AsyncCallback callback); - void getTableMetadata(TRId trId, - AsyncCallback> callback); + void getTableMetadata(TRId trId, AsyncCallback> callback); void getTRMetadata(TRId trId, AsyncCallback> callback); - void getTimeTableId(PeriodDataType periodDataType, - AsyncCallback callback); + void getTimeTableId(PeriodDataType periodDataType, AsyncCallback callback); void getColumns(AsyncCallback> callback); void getColumns(TRId trId, AsyncCallback> callback); - void getColumnWithViewColumnIncluded(TRId trId, - AsyncCallback> callback); + void getColumnWithViewColumnIncluded(TRId trId, AsyncCallback> callback); - void getColumnWithOnlyViewColumnInRel(TRId trId, - AsyncCallback> callback); + void getColumnWithOnlyViewColumnInRel(TRId trId, AsyncCallback> callback); - void getColumnsForStatistical(TRId trId, - AsyncCallback> callback); + void getColumnsForStatistical(TRId trId, AsyncCallback> callback); - void getColumnsForDimension(TRId trId, - AsyncCallback> callback); + void getColumnsForDimension(TRId trId, AsyncCallback> callback); - void getColumn(TRId trId, String columnName, - AsyncCallback callback); + void getColumn(TRId trId, String columnName, AsyncCallback callback); - void getColumn(String columnLocalId, TRId trId, - AsyncCallback callback); + void getColumn(String columnLocalId, TRId trId, AsyncCallback callback); void getConnection(RefColumn refColumn, AsyncCallback callback); void closeAllTabularResources(AsyncCallback callback); - void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId, - AsyncCallback callback); + void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId, AsyncCallback callback); void closeTabularResource(TRId closeTRId, AsyncCallback callback); void setActiveTabularResource(TRId activeTRId, AsyncCallback callback); // Task - void startTaskResubmit(TaskResubmitSession taskResubmitSession, - AsyncCallback callback); + void startTaskResubmit(TaskResubmitSession taskResubmitSession, AsyncCallback callback); - void startTaskResume(TaskResumeSession taskResumeSession, - AsyncCallback callback); + void startTaskResume(TaskResumeSession taskResumeSession, AsyncCallback callback); // Validations - void getValidationsTasksMetadata(TRId trId, - AsyncCallback callback); + void getValidationsTasksMetadata(TRId trId, AsyncCallback callback); - void getTableValidationsMetadata(TRId trId, - AsyncCallback callback); + void getTableValidationsMetadata(TRId trId, AsyncCallback callback); - void getValidationColumns(TRId trId, String columnName, - AsyncCallback> callback); + void getValidationColumns(TRId trId, String columnName, AsyncCallback> callback); - void getValidationColumns(String columnLocalId, TRId trId, - AsyncCallback> callback); + void getValidationColumns(String columnLocalId, TRId trId, AsyncCallback> callback); void startValidationsDelete(TRId trId, AsyncCallback callback); // RollBack - void startRollBack(RollBackSession rollBackSession, - AsyncCallback callback); + void startRollBack(RollBackSession rollBackSession, AsyncCallback callback); void startDiscard(TRId trId, AsyncCallback callback); // Share void setShare(ShareTabResource shareInfo, AsyncCallback callback); - void setShareTemplate(ShareTemplate shareTemplate, - AsyncCallback callback); + void setShareTemplate(ShareTemplate shareTemplate, AsyncCallback callback); void setShareRule(ShareRule shareRule, AsyncCallback callback); // CodelistPagingLoaded void setCodelistsPagingLoader(AsyncCallback callback); - void getCodelistsPagingLoader( - CodelistPagingLoadConfig codelistPagingLoadConfig, + void getCodelistsPagingLoader(CodelistPagingLoadConfig codelistPagingLoadConfig, AsyncCallback callback); // Open void tdOpen(TDOpenSession tdOpenSession, AsyncCallback callback); // Clone - void startCloneTabularResource( - CloneTabularResourceSession cloneTabularResourceSession, + void startCloneTabularResource(CloneTabularResourceSession cloneTabularResourceSession, AsyncCallback callback); // SDMX @@ -261,82 +234,61 @@ public interface TDGWTServiceAsync { void getAgencies(AsyncCallback> callback); - void setSDMXRegistrySource(SDMXRegistrySource sdmxRegistrySource, - AsyncCallback callback); + void setSDMXRegistrySource(SDMXRegistrySource sdmxRegistrySource, AsyncCallback callback); // Import SDMX - void startSDMXImport(SDMXImportSession sdmxImportSession, - AsyncCallback callback); + void startSDMXImport(SDMXImportSession sdmxImportSession, AsyncCallback callback); // Import CSV - void setCSVSession(CSVImportSession csvImportSession, - AsyncCallback callback); + void setCSVSession(CSVImportSession csvImportSession, AsyncCallback callback); - void getFileFromWorkspace(CSVImportSession csvImportSession, - AsyncCallback callback); + void getFileFromWorkspace(CSVImportSession csvImportSession, AsyncCallback callback); void getAvailableCharset(AsyncCallback callback); - void configureCSVParser(String encoding, HeaderPresence headerPresence, - char delimiter, char comment, + void configureCSVParser(String encoding, HeaderPresence headerPresence, char delimiter, char comment, AsyncCallback> callback); void checkCSV(long errorsLimit, AsyncCallback callback); - void startCSVImport(CSVImportSession csvImportSession, - AsyncCallback callback); + void startCSVImport(CSVImportSession csvImportSession, AsyncCallback callback); // Export CSV - void getAvailableCharsetForExport( - AsyncCallback callback); + void getAvailableCharsetForExport(AsyncCallback callback); - void startCSVExport(CSVExportSession csvExportSession, - AsyncCallback callback); + void startCSVExport(CSVExportSession csvExportSession, AsyncCallback callback); // Export SDMX - void startSDMXExport(SDMXExportSession exportSession, - AsyncCallback callback); + void startSDMXExport(SDMXExportSession exportSession, AsyncCallback callback); // Export Template SDMX - void startSDMXTemplateExport( - SDMXTemplateExportSession sdmxTemplateExportSession, - AsyncCallback callback); + void startSDMXTemplateExport(SDMXTemplateExportSession sdmxTemplateExportSession, AsyncCallback callback); // Export JSON - void startJSONExport(JSONExportSession jsonExportSession, - AsyncCallback callback); + void startJSONExport(JSONExportSession jsonExportSession, AsyncCallback callback); // Table Operation - void startChangeTableType(ChangeTableTypeSession changeTableTypeSession, - AsyncCallback callback); + void startChangeTableType(ChangeTableTypeSession changeTableTypeSession, AsyncCallback callback); void startUnion(UnionSession unionSession, AsyncCallback callback); // Rows Operation - void startEditRow(EditRowSession editRowSession, - AsyncCallback callback); + void startEditRow(EditRowSession editRowSession, AsyncCallback callback); - void startDeleteRows(DeleteRowsSession deleteRowsSession, - AsyncCallback callback); + void startDeleteRows(DeleteRowsSession deleteRowsSession, AsyncCallback callback); - void startDuplicates(DuplicatesSession duplicatesSession, - AsyncCallback callback); + void startDuplicates(DuplicatesSession duplicatesSession, AsyncCallback callback); // Column Operation - void startChangeColumnType(ChangeColumnTypeSession changeColumnTypeSession, - AsyncCallback callback); + void startChangeColumnType(ChangeColumnTypeSession changeColumnTypeSession, AsyncCallback callback); - void startAddColumn(AddColumnSession addColumnSession, - AsyncCallback callback); + void startAddColumn(AddColumnSession addColumnSession, AsyncCallback callback); - void startDeleteColumn(DeleteColumnSession deleteColumnSession, - AsyncCallback callback); + void startDeleteColumn(DeleteColumnSession deleteColumnSession, AsyncCallback callback); - void startLabelColumn(LabelColumnSession labelColumnSession, - AsyncCallback callback); + void startLabelColumn(LabelColumnSession labelColumnSession, AsyncCallback callback); - void startChangeColumnsPosition( - ChangeColumnsPositionSession changeColumnsPositionSession, + void startChangeColumnsPosition(ChangeColumnsPositionSession changeColumnsPositionSession, AsyncCallback callback); /* @@ -353,36 +305,26 @@ public interface TDGWTServiceAsync { */ // BatchReplace Operation - void getOccurrencesForBatchReplace( - OccurrencesForReplaceBatchColumnSession occurrencesForReplaceBatchColumnSession, + void getOccurrencesForBatchReplace(OccurrencesForReplaceBatchColumnSession occurrencesForReplaceBatchColumnSession, AsyncCallback> callback); - void startReplaceBatchColumn( - ReplaceBatchColumnSession replaceBatchColumnSession, - AsyncCallback callback); + void startReplaceBatchColumn(ReplaceBatchColumnSession replaceBatchColumnSession, AsyncCallback callback); // Replace Operation - void startReplaceColumn(ReplaceColumnSession replaceColumnSession, - AsyncCallback callback); + void startReplaceColumn(ReplaceColumnSession replaceColumnSession, AsyncCallback callback); - void startReplaceByExternal( - ReplaceByExternalSession replaceByExternalSession, - AsyncCallback callback); + void startReplaceByExternal(ReplaceByExternalSession replaceByExternalSession, AsyncCallback callback); // Templates void getTemplates(AsyncCallback> callback); - void getTemplatesForDSDExport( - AsyncCallback> callback); + void getTemplatesForDSDExport(AsyncCallback> callback); - void getTemplateColumnsData(String templateId, - AsyncCallback> callback); + void getTemplateColumnsData(String templateId, AsyncCallback> callback); - void startTemplateApply(TemplateApplySession templateDeleteSession, - AsyncCallback callback); + void startTemplateApply(TemplateApplySession templateDeleteSession, AsyncCallback callback); - void templateDelete(TemplateDeleteSession templateDeleteSession, - AsyncCallback callback); + void templateDelete(TemplateDeleteSession templateDeleteSession, AsyncCallback callback); // Locales void getLocales(AsyncCallback> callback); @@ -400,82 +342,64 @@ public interface TDGWTServiceAsync { void getLastOperationInfo(TRId trId, AsyncCallback callback); // Helper Extract Codelist - void startExtractCodelist(ExtractCodelistSession extractCodelistSession, - AsyncCallback callback); + void startExtractCodelist(ExtractCodelistSession extractCodelistSession, AsyncCallback callback); // Helper Codelist Mapping Import - void setCodelistMappingSession( - CodelistMappingSession codelistMappingSession, - AsyncCallback callback); + void setCodelistMappingSession(CodelistMappingSession codelistMappingSession, AsyncCallback callback); - void getFileFromWorkspace(CodelistMappingSession codelistMappingSession, - AsyncCallback callback); + void getFileFromWorkspace(CodelistMappingSession codelistMappingSession, AsyncCallback callback); - void startCodelistMappingImport( - CodelistMappingSession codelistMappingSession, - AsyncCallback callback); + void startCodelistMappingImport(CodelistMappingSession codelistMappingSession, AsyncCallback callback); // Normalization - void startNormalization(NormalizationSession normalizationSession, - AsyncCallback callback); + void startNormalization(NormalizationSession normalizationSession, AsyncCallback callback); // Denormalization - void startDenormalization(DenormalizationSession denormalizationSession, - AsyncCallback callback); + void startDenormalization(DenormalizationSession denormalizationSession, AsyncCallback callback); // Operation Monitor - void getOperationMonitor(OperationMonitorSession operationMonitorSession, - AsyncCallback callback); + void getOperationMonitor(OperationMonitorSession operationMonitorSession, AsyncCallback callback); - void getBackgroundOperationMonitor( - BackgroundOperationMonitorSession backgroundOperationMonitorSession, + void getBackgroundOperationMonitor(BackgroundOperationMonitorSession backgroundOperationMonitorSession, AsyncCallback> callback); - void getBackgroundOperationMonitorForSpecificTask( - OperationMonitorSession operationMonitorSession, + void getBackgroundOperationMonitorForSpecificTask(OperationMonitorSession operationMonitorSession, AsyncCallback callback); // File Upload Monitor void getFileUploadMonitor(AsyncCallback callback); // ResourceTD - void getResourcesTD(TRId trId, - AsyncCallback> callback); + void getResourcesTD(TRId trId, AsyncCallback> callback); void getResourcesTDByType(TRId trId, ResourceTDType reourceTDType, AsyncCallback> callback); - void removeResource(RemoveResourceSession removeResourceSession, - AsyncCallback callback); + void removeResource(RemoveResourceSession removeResourceSession, AsyncCallback callback); - void saveResource(SaveResourceSession saveResourceSession, - AsyncCallback callback); + void saveResource(SaveResourceSession saveResourceSession, AsyncCallback callback); // GIS MAP - void startMapCreation(MapCreationSession mapCreationSession, - AsyncCallback callback); + void startMapCreation(MapCreationSession mapCreationSession, AsyncCallback callback); // DataMiner - void startDataMinerOperation( - DataMinerOperationSession dataMinerOperationSession, - AsyncCallback callback); + void startDataMinerOperation(DataMinerOperationSession dataMinerOperationSession, AsyncCallback callback); // Chart - void startChartTopRating(ChartTopRatingSession chartTopRatingSession, - AsyncCallback callback); + void startChartTopRating(ChartTopRatingSession chartTopRatingSession, AsyncCallback callback); // Geospatial - void startGeospatialCreateCoordinates( - GeospatialCreateCoordinatesSession geospatialCreateCoordinatesSession, + void startGeospatialCreateCoordinates(GeospatialCreateCoordinatesSession geospatialCreateCoordinatesSession, AsyncCallback callback); - void startGeospatialDownscaleCSquare( - GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession, + void startGeospatialDownscaleCSquare(GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession, AsyncCallback callback); // Geometry - void startGeometryCreatePoint( - GeometryCreatePointSession geometryCreatePointSession, + void startGeometryCreatePoint(GeometryCreatePointSession geometryCreatePointSession, AsyncCallback callback); + // Retrieve the URL of default SDMX Registry + void getDefaultSDMXRegistryURL(AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index f79156e..7dd8e40 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -26,6 +26,8 @@ public class SessionConstants { public static final String TR_TASK_MANAGER = "TR_TASK_MANAGER"; + public static final String SDMX_INTERNAL_REGISTRY_URL = "SDMX_INTERNAL_REGISTRY_URL"; + public static final String SDMX_REGISTRY_SOURCE = "SDMX_REGISTRY_SOURCE"; public static final String SDMX_CLIENT_ATTRIBUTE = "SDMX_CLIENT"; @@ -133,4 +135,6 @@ public class SessionConstants { public static final String COLUMN_FILTER_SESSION_TASK = "COLUMN_FILTER_SESSION_TASK"; + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index 190d1ef..8d4e06c 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -536,6 +536,22 @@ public class SessionUtil { } + public static void setInternalSDMXRegistryURLSession(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, + String defaultSDMXRegistryUrl) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.SDMX_INTERNAL_REGISTRY_URL, defaultSDMXRegistryUrl); + } + + public static String getInternalSDMXRegistryURLSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + String defaultSDMXRegistryURL = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.SDMX_INTERNAL_REGISTRY_URL); + return defaultSDMXRegistryURL; + } + + + public static void setSDMXExportSession(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, SDMXExportSession sdmxExportSession) { SessionOp sessionOp = new SessionOp<>(); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 1bca60d..d750909 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -111,6 +111,7 @@ import org.gcube.portlets.user.td.gwtservice.server.encoding.EncodingPGSupported import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; +import org.gcube.portlets.user.td.gwtservice.server.is.ISUtils; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4AddColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4CSVExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4CSVImport; @@ -4429,11 +4430,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi // / switch (exportSession.getExportType()) { case CODELIST: - OpExecution4SDMXCodelistExport opExC = new OpExecution4SDMXCodelistExport(service, exportSession); + OpExecution4SDMXCodelistExport opExC = new OpExecution4SDMXCodelistExport(httpRequest, + serviceCredentials, service, exportSession); director.setOperationExecutionBuilder(opExC); break; case DATASET: - OpExecution4SDMXDatasetExport opExD = new OpExecution4SDMXDatasetExport(service, exportSession); + OpExecution4SDMXDatasetExport opExD = new OpExecution4SDMXDatasetExport(httpRequest, serviceCredentials, + service, exportSession); director.setOperationExecutionBuilder(opExD); break; case GENERIC: @@ -4496,8 +4499,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi OpExecutionDirector director = new OpExecutionDirector(); // / - OpExecution4SDMXTemplateExport opExD = new OpExecution4SDMXTemplateExport(service, - sdmxTemplateExportSession); + OpExecution4SDMXTemplateExport opExD = new OpExecution4SDMXTemplateExport(httpRequest, serviceCredentials, + service, sdmxTemplateExportSession); director.setOperationExecutionBuilder(opExD); director.constructOperationExecution(); @@ -8940,4 +8943,43 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi } + @Override + public String getDefaultSDMXRegistryURL() throws TDGWTServiceException { + HttpServletRequest httpRequest = null; + try { + httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest); + + String defaultSDMXRegistryURL = SessionUtil.getInternalSDMXRegistryURLSession(httpRequest, + serviceCredentials); + + if (defaultSDMXRegistryURL == null || defaultSDMXRegistryURL.isEmpty()) { + defaultSDMXRegistryURL = ISUtils.retrieveInternalSDMXRegistryURL(); + if (defaultSDMXRegistryURL != null && !defaultSDMXRegistryURL.isEmpty()) { + SessionUtil.setInternalSDMXRegistryURLSession(httpRequest, serviceCredentials, + defaultSDMXRegistryURL); + int pos = defaultSDMXRegistryURL.indexOf("FusionRegistry"); + defaultSDMXRegistryURL = defaultSDMXRegistryURL.substring(0, pos + 15); + + } + } else { + int pos = defaultSDMXRegistryURL.indexOf("FusionRegistry"); + defaultSDMXRegistryURL = defaultSDMXRegistryURL.substring(0, pos + 15); + } + + logger.debug("Default SDMXRegistry URL: " + defaultSDMXRegistryURL); + return defaultSDMXRegistryURL; + + } catch (TDGWTServiceException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + ResourceBundle messages = getResourceBundle(httpRequest); + throw new TDGWTServiceException(messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); + } catch (Throwable e) { + logger.error("getDefaultSDMXRegistryURL(): " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving default SDMX Regitry URL: " + e.getLocalizedMessage()); + } + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/is/ISUtils.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/is/ISUtils.java new file mode 100644 index 0000000..1ddc13d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/is/ISUtils.java @@ -0,0 +1,56 @@ +package org.gcube.portlets.user.td.gwtservice.server.is; + +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.util.List; + +import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.Profile; +import org.gcube.common.resources.gcore.utils.Group; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class ISUtils { + + private static Logger logger = LoggerFactory.getLogger(ISUtils.class); + + public static String retrieveInternalSDMXRegistryURL() { + String sdmxRegistryURL = null; + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Category/text() eq 'SDMX'") + .addCondition("$resource/Profile/Name/text() eq 'SDMXRegistry'"); + DiscoveryClient client = clientFor(ServiceEndpoint.class); + List listService = client.submit(query); + if (listService.size() > 0) { + ServiceEndpoint serviceEnd = listService.get(0); + if (serviceEnd != null) { + Profile prof = serviceEnd.profile(); + Group groupA = prof.accessPoints(); + for (AccessPoint acc : groupA) { + if (acc.description().compareTo("REST Interface v2.1") == 0) { + sdmxRegistryURL = acc.address(); + break; + } + } + } else { + + } + } else { + + } + logger.debug("Retrieved URL of the default SDMX Registry: " + sdmxRegistryURL); + return sdmxRegistryURL; + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXCodelistExport.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXCodelistExport.java index 4e52cdb..667203d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXCodelistExport.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXCodelistExport.java @@ -1,26 +1,21 @@ package org.gcube.portlets.user.td.gwtservice.server.opexecution; -import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; -import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; - import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.gcube.common.resources.gcore.ServiceEndpoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.Profile; -import org.gcube.common.resources.gcore.utils.Group; +import javax.servlet.http.HttpServletRequest; + import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.is.ISUtils; import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials; import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,14 +27,17 @@ import org.slf4j.LoggerFactory; * */ public class OpExecution4SDMXCodelistExport extends OpExecutionBuilder { - private static Logger logger = LoggerFactory - .getLogger(OpExecution4SDMXCodelistExport.class); + private static Logger logger = LoggerFactory.getLogger(OpExecution4SDMXCodelistExport.class); + private HttpServletRequest httpRequest; + private ServiceCredentials serviceCredentials; private TabularDataService service; private SDMXExportSession sdmxExportSession; - public OpExecution4SDMXCodelistExport(TabularDataService service, - SDMXExportSession sdmxExportSession) { + public OpExecution4SDMXCodelistExport(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, + TabularDataService service, SDMXExportSession sdmxExportSession) { + this.httpRequest = httpRequest; + this.serviceCredentials = serviceCredentials; this.service = service; this.sdmxExportSession = sdmxExportSession; } @@ -52,8 +50,7 @@ public class OpExecution4SDMXCodelistExport extends OpExecutionBuilder { // http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/ if (sdmxExportSession != null) { - if (sdmxExportSession.getRegistryBaseUrl() != null - && !sdmxExportSession.getRegistryBaseUrl().isEmpty()) { + if (sdmxExportSession.getRegistryBaseUrl() != null && !sdmxExportSession.getRegistryBaseUrl().isEmpty()) { destination = sdmxExportSession.getRegistryBaseUrl(); } else { internalRegistry = true; @@ -63,37 +60,22 @@ public class OpExecution4SDMXCodelistExport extends OpExecutionBuilder { } if (internalRegistry) { - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Category/text() eq 'SDMX'") - .addCondition( - "$resource/Profile/Name/text() eq 'SDMXRegistry'"); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List listService = client.submit(query); - if (listService.size() > 0) { - ServiceEndpoint serviceEnd = listService.get(0); - if (serviceEnd != null) { - Profile prof = serviceEnd.profile(); - Group groupA = prof.accessPoints(); - for (AccessPoint acc : groupA) { - if (acc.description().compareTo("REST Interface v2.1") == 0) { - destination = acc.address(); - break; - } - } - } else { - + destination = SessionUtil.getInternalSDMXRegistryURLSession(httpRequest, serviceCredentials); + if (destination == null || destination.isEmpty()) { + destination = ISUtils.retrieveInternalSDMXRegistryURL(); + if(destination!=null&&!destination.isEmpty()){ + SessionUtil.setInternalSDMXRegistryURLSession(httpRequest, serviceCredentials, destination); } - } else { - } } + if (destination == null) { logger.debug("Destination: " + destination); throw new TDGWTServiceException("SDMX Service not discovered"); } - OperationDefinition operationDefinition = OperationDefinitionMap.map( - OperationsId.SDMXCodelistExport.toString(), service); + OperationDefinition operationDefinition = OperationDefinitionMap.map(OperationsId.SDMXCodelistExport.toString(), + service); Map map = new HashMap(); @@ -102,8 +84,7 @@ public class OpExecution4SDMXCodelistExport extends OpExecutionBuilder { map.put(Constants.PARAMETER_ID, sdmxExportSession.getId()); map.put(Constants.PARAMETER_VERSION, sdmxExportSession.getVersion()); - OperationExecution invocation = new OperationExecution( - operationDefinition.getOperationId(), map); + OperationExecution invocation = new OperationExecution(operationDefinition.getOperationId(), map); operationExecutionSpec.setOp(invocation); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXDatasetExport.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXDatasetExport.java index 27f6e8a..e20d0ee 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXDatasetExport.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXDatasetExport.java @@ -1,26 +1,21 @@ package org.gcube.portlets.user.td.gwtservice.server.opexecution; -import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; -import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; - import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.gcube.common.resources.gcore.ServiceEndpoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.Profile; -import org.gcube.common.resources.gcore.utils.Group; +import javax.servlet.http.HttpServletRequest; + import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.is.ISUtils; import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials; import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,14 +27,15 @@ import org.slf4j.LoggerFactory; * */ public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder { - private static Logger logger = LoggerFactory - .getLogger(OpExecution4SDMXDatasetExport.class); + private static Logger logger = LoggerFactory.getLogger(OpExecution4SDMXDatasetExport.class); + private HttpServletRequest httpRequest; + private ServiceCredentials serviceCredentials; private TabularDataService service; private SDMXExportSession sdmxExportSession; - public OpExecution4SDMXDatasetExport(TabularDataService service, - SDMXExportSession sdmxExportSession) { + public OpExecution4SDMXDatasetExport(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, + TabularDataService service, SDMXExportSession sdmxExportSession) { this.service = service; this.sdmxExportSession = sdmxExportSession; } @@ -52,8 +48,7 @@ public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder { // http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/ if (sdmxExportSession != null) { - if (sdmxExportSession.getRegistryBaseUrl() != null - && !sdmxExportSession.getRegistryBaseUrl().isEmpty()) { + if (sdmxExportSession.getRegistryBaseUrl() != null && !sdmxExportSession.getRegistryBaseUrl().isEmpty()) { destination = sdmxExportSession.getRegistryBaseUrl(); } else { internalRegistry = true; @@ -63,28 +58,12 @@ public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder { } if (internalRegistry) { - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Category/text() eq 'SDMX'") - .addCondition( - "$resource/Profile/Name/text() eq 'SDMXRegistry'"); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List listService = client.submit(query); - if (listService.size() > 0) { - ServiceEndpoint serviceEnd = listService.get(0); - if (serviceEnd != null) { - Profile prof = serviceEnd.profile(); - Group groupA = prof.accessPoints(); - for (AccessPoint acc : groupA) { - if (acc.description().compareTo("REST Interface v2.1") == 0) { - destination = acc.address(); - break; - } - } - } else { - + destination = SessionUtil.getInternalSDMXRegistryURLSession(httpRequest, serviceCredentials); + if (destination == null || destination.isEmpty()) { + destination = ISUtils.retrieveInternalSDMXRegistryURL(); + if(destination!=null&&!destination.isEmpty()){ + SessionUtil.setInternalSDMXRegistryURLSession(httpRequest, serviceCredentials, destination); } - } else { - } } if (destination == null) { @@ -92,8 +71,8 @@ public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder { throw new TDGWTServiceException("SDMX Service not discovered"); } - OperationDefinition operationDefinition = OperationDefinitionMap.map( - OperationsId.SDMXDatasetExport.toString(), service); + OperationDefinition operationDefinition = OperationDefinitionMap.map(OperationsId.SDMXDatasetExport.toString(), + service); Map map = new HashMap(); @@ -103,8 +82,7 @@ public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder { map.put(Constants.PARAMETER_VERSION, sdmxExportSession.getVersion()); map.put(Constants.PARAMETER_OBSVALUECOLUMN, sdmxExportSession.getObsValueColumn().getColumnId()); map.put(Constants.PARAMETER_EXCEL, sdmxExportSession.isExcel()); - OperationExecution invocation = new OperationExecution( - operationDefinition.getOperationId(), map); + OperationExecution invocation = new OperationExecution(operationDefinition.getOperationId(), map); operationExecutionSpec.setOp(invocation); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXTemplateExport.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXTemplateExport.java index f7e8889..7f27242 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXTemplateExport.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4SDMXTemplateExport.java @@ -1,16 +1,10 @@ package org.gcube.portlets.user.td.gwtservice.server.opexecution; -import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; -import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; - import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.gcube.common.resources.gcore.ServiceEndpoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.Profile; -import org.gcube.common.resources.gcore.utils.Group; +import javax.servlet.http.HttpServletRequest; + import org.gcube.data.analysis.tabulardata.commons.templates.model.Template; import org.gcube.data.analysis.tabulardata.commons.webservice.exception.NoSuchTemplateException; import org.gcube.data.analysis.tabulardata.commons.webservice.types.TemplateDescription; @@ -18,13 +12,14 @@ import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.O import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.template.TemplateId; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.is.ISUtils; import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials; import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXTemplateExportSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,14 +31,15 @@ import org.slf4j.LoggerFactory; * */ public class OpExecution4SDMXTemplateExport extends OpExecutionBuilder { - private static Logger logger = LoggerFactory - .getLogger(OpExecution4SDMXTemplateExport.class); + private static Logger logger = LoggerFactory.getLogger(OpExecution4SDMXTemplateExport.class); + private HttpServletRequest httpRequest; + private ServiceCredentials serviceCredentials; private TabularDataService service; private SDMXTemplateExportSession sdmxTemplateExportSession; - public OpExecution4SDMXTemplateExport(TabularDataService service, - SDMXTemplateExportSession sdmxTemplateExportSession) { + public OpExecution4SDMXTemplateExport(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, + TabularDataService service, SDMXTemplateExportSession sdmxTemplateExportSession) { this.service = service; this.sdmxTemplateExportSession = sdmxTemplateExportSession; } @@ -57,8 +53,7 @@ public class OpExecution4SDMXTemplateExport extends OpExecutionBuilder { if (sdmxTemplateExportSession != null) { if (sdmxTemplateExportSession.getRegistryBaseUrl() != null - && !sdmxTemplateExportSession.getRegistryBaseUrl() - .isEmpty()) { + && !sdmxTemplateExportSession.getRegistryBaseUrl().isEmpty()) { destination = sdmxTemplateExportSession.getRegistryBaseUrl(); } else { internalRegistry = true; @@ -68,30 +63,15 @@ public class OpExecution4SDMXTemplateExport extends OpExecutionBuilder { } if (internalRegistry) { - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Category/text() eq 'SDMX'") - .addCondition( - "$resource/Profile/Name/text() eq 'SDMXRegistry'"); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List listService = client.submit(query); - if (listService.size() > 0) { - ServiceEndpoint serviceEnd = listService.get(0); - if (serviceEnd != null) { - Profile prof = serviceEnd.profile(); - Group groupA = prof.accessPoints(); - for (AccessPoint acc : groupA) { - if (acc.description().compareTo("REST Interface v2.1") == 0) { - destination = acc.address(); - break; - } - } - } else { - + destination = SessionUtil.getInternalSDMXRegistryURLSession(httpRequest, serviceCredentials); + if (destination == null || destination.isEmpty()) { + destination = ISUtils.retrieveInternalSDMXRegistryURL(); + if(destination!=null&&!destination.isEmpty()){ + SessionUtil.setInternalSDMXRegistryURLSession(httpRequest, serviceCredentials, destination); } - } else { - } } + if (destination == null) { logger.debug("Destination: " + destination); throw new TDGWTServiceException("SDMX Service not discovered"); @@ -99,35 +79,29 @@ public class OpExecution4SDMXTemplateExport extends OpExecutionBuilder { TemplateDescription templateDescriptor; try { - templateDescriptor = service.getTemplate(new TemplateId( - sdmxTemplateExportSession.getTemplateData().getId())); + templateDescriptor = service + .getTemplate(new TemplateId(sdmxTemplateExportSession.getTemplateData().getId())); } catch (NoSuchTemplateException e) { - logger.debug( - "Error retrieving template: " + e.getLocalizedMessage(), e); - throw new TDGWTServiceException("Error retrieving template: " - + e.getLocalizedMessage()); + logger.debug("Error retrieving template: " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving template: " + e.getLocalizedMessage()); } - OperationDefinition operationDefinition = OperationDefinitionMap.map( - OperationsId.SDMXTemplateExport.toString(), service); - - HashMap templateMap=new HashMap(); - templateMap.put(Constants.PARAMETER_TEMPLATE,templateDescriptor.getTemplate()); - + OperationDefinition operationDefinition = OperationDefinitionMap.map(OperationsId.SDMXTemplateExport.toString(), + service); + + HashMap templateMap = new HashMap(); + templateMap.put(Constants.PARAMETER_TEMPLATE, templateDescriptor.getTemplate()); + Map map = new HashMap(); map.put(Constants.PARAMETER_REGISTRYBASEURL, destination); - map.put(Constants.PARAMETER_AGENCY, - sdmxTemplateExportSession.getAgencyId()); + map.put(Constants.PARAMETER_AGENCY, sdmxTemplateExportSession.getAgencyId()); map.put(Constants.PARAMETER_ID, sdmxTemplateExportSession.getId()); - map.put(Constants.PARAMETER_VERSION, - sdmxTemplateExportSession.getVersion()); - map.put(Constants.PARAMETER_OBSVALUECOLUMN, sdmxTemplateExportSession - .getObsValueColumn().getColumnId()); + map.put(Constants.PARAMETER_VERSION, sdmxTemplateExportSession.getVersion()); + map.put(Constants.PARAMETER_OBSVALUECOLUMN, sdmxTemplateExportSession.getObsValueColumn().getColumnId()); map.put(Constants.PARAMETER_EXCEL, sdmxTemplateExportSession.isExcel()); map.put(Constants.PARAMETER_TEMPLATE, templateMap); - OperationExecution invocation = new OperationExecution( - operationDefinition.getOperationId(), map); + OperationExecution invocation = new OperationExecution(operationDefinition.getOperationId(), map); operationExecutionSpec.setOp(invocation); }