refs 5870: TDM - adding new functionalities to portlets

Task-Url: https://support.d4science.org/issues/5870

Updated to support SDMX Dataset export

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@142035 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-02-01 17:54:23 +00:00
parent ea37378b80
commit cf0dc3ec40
7 changed files with 208 additions and 35 deletions

View File

@ -200,9 +200,6 @@
</dependency> </dependency>
<!-- Storage --> <!-- Storage -->
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>

View File

@ -139,6 +139,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Repl
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumnByExpression; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumnByExpression;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistExport;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistImport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistImport;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXDatasetExport;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4StatisticalOperation; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4StatisticalOperation;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4TimeAggregation; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4TimeAggregation;
@ -5132,6 +5133,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
"Error no table present in session"); "Error no table present in session");
} }
if (exportSession == null) {
logger.error("Error in SDMX Export: exportSession is null!");
throw new TDGWTServiceException(
"Error in SDMX Export: exportSession is null!!");
}
SessionUtil.setSDMXExportSession(httpRequest, serviceCredentials, SessionUtil.setSDMXExportSession(httpRequest, serviceCredentials,
exportSession); exportSession);
@ -5151,11 +5159,26 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceLocked(tabularResource, httpRequest, checkTabularResourceLocked(tabularResource, httpRequest,
serviceCredentials); serviceCredentials);
// /
OpExecution4SDMXCodelistExport opEx = new OpExecution4SDMXCodelistExport(
service, exportSession);
OpExecutionDirector director = new OpExecutionDirector(); OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx); // /
switch (exportSession.getExportType()) {
case CODELIST:
OpExecution4SDMXCodelistExport opExC = new OpExecution4SDMXCodelistExport(
service, exportSession);
director.setOperationExecutionBuilder(opExC);
break;
case DATASET:
OpExecution4SDMXDatasetExport opExD = new OpExecution4SDMXDatasetExport(
service, exportSession);
director.setOperationExecutionBuilder(opExD);
break;
case GENERIC:
default:
logger.error("Error in SDMX Export: Only Codelist and Dataset are supported!");
throw new TDGWTServiceException(
"Error in SDMXExport: Only Codelist and Dataset are supported!");
}
director.constructOperationExecution(); director.constructOperationExecution();
OperationExecution invocation = director.getOperationExecution(); OperationExecution invocation = director.getOperationExecution();

View File

@ -98,9 +98,9 @@ public class OpExecution4SDMXCodelistExport extends OpExecutionBuilder {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put(Constants.PARAMETER_REGISTRYBASEURL, destination); map.put(Constants.PARAMETER_REGISTRYBASEURL, destination);
map.put(Constants.PARAMETER_AGENCY, "SDMX"); map.put(Constants.PARAMETER_AGENCY, sdmxExportSession.getAgencyName());
map.put(Constants.PARAMETER_ID, "NEW_CL_DIVISION"); map.put(Constants.PARAMETER_ID, sdmxExportSession.getId());
map.put(Constants.PARAMETER_VERSION, "2.0"); map.put(Constants.PARAMETER_VERSION, sdmxExportSession.getVersion());
OperationExecution invocation = new OperationExecution( OperationExecution invocation = new OperationExecution(
operationDefinition.getOperationId(), map); operationDefinition.getOperationId(), map);

View File

@ -0,0 +1,111 @@
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 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.trservice.OperationDefinitionMap;
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;
/**
* Operation Execution for sdmx Dataset export
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4SDMXDatasetExport extends OpExecutionBuilder {
private static Logger logger = LoggerFactory
.getLogger(OpExecution4SDMXDatasetExport.class);
private TabularDataService service;
private SDMXExportSession sdmxExportSession;
public OpExecution4SDMXDatasetExport(TabularDataService service,
SDMXExportSession sdmxExportSession) {
this.service = service;
this.sdmxExportSession = sdmxExportSession;
}
@Override
public void buildOpEx() throws TDGWTServiceException {
logger.debug(sdmxExportSession.toString());
boolean internalRegistry = false;
String destination = null;// Es:
// http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/
if (sdmxExportSession != null) {
if (sdmxExportSession.getRegistryBaseUrl() != null
&& !sdmxExportSession.getRegistryBaseUrl().isEmpty()) {
destination = sdmxExportSession.getRegistryBaseUrl();
} else {
internalRegistry = true;
}
} else {
internalRegistry = true;
}
if (internalRegistry) {
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq 'SDMX'")
.addCondition(
"$resource/Profile/Name/text() eq 'SDMXRegistry'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> listService = client.submit(query);
if (listService.size() > 0) {
ServiceEndpoint serviceEnd = listService.get(0);
if (serviceEnd != null) {
Profile prof = serviceEnd.profile();
Group<AccessPoint> groupA = prof.accessPoints();
for (AccessPoint acc : groupA) {
if (acc.description().compareTo("REST Interface v2.1") == 0) {
destination = acc.address();
break;
}
}
} else {
}
} else {
}
}
if (destination == null) {
logger.debug("Destination: " + destination);
throw new TDGWTServiceException("SDMX Service not discovered");
}
OperationDefinition operationDefinition = OperationDefinitionMap.map(
OperationsId.SDMXDatasetExport.toString(), service);
Map<String, Object> map = new HashMap<String, Object>();
map.put(Constants.PARAMETER_REGISTRYBASEURL, destination);
map.put(Constants.PARAMETER_AGENCY, sdmxExportSession.getAgencyName());
map.put(Constants.PARAMETER_ID, sdmxExportSession.getId());
map.put(Constants.PARAMETER_VERSION, sdmxExportSession.getVersion());
map.put(Constants.PARAMETER_OBSVALUECOLUMN, sdmxExportSession.getObsValueColumn().getColumnId());
OperationExecution invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -29,7 +29,15 @@ public class Constants {
public final static String FILE_XML_MIMETYPE = "application/xml"; public final static String FILE_XML_MIMETYPE = "application/xml";
public final static String FILE_CSV_MIMETYPE = "text/csv"; public final static String FILE_CSV_MIMETYPE = "text/csv";
public static final String SDMX_CODELIST_EXPORT_DEFAULT_ID = "NEW_CL_DIVISION";
public static final String SDMX_CODELIST_EXPORT_DEFAULT_AGENCY = "SDMX";
public static final String SDMX_CODELIST_EXPORT_DEFAULT_VERSION = "2.0";
public static final String SDMX_DATASET_EXPORT_DEFAULT_ID = "NEW_DS_DIVISION";
public static final String SDMX_DATASET_EXPORT_DEFAULT_AGENCY = "SDMX";
public static final String SDMX_DATASET_EXPORT_DEFAULT_VERSION = "1.0";
public static final String PARAMETER_ENCODING = "encoding"; public static final String PARAMETER_ENCODING = "encoding";
public static final String PARAMETER_HASHEADER = "hasHeader"; public static final String PARAMETER_HASHEADER = "hasHeader";
public static final String PARAMETER_FIELDMASK = "fieldMask"; public static final String PARAMETER_FIELDMASK = "fieldMask";
@ -43,6 +51,7 @@ public class Constants {
public static final String PARAMETER_REGISTRYBASEURL = "registryBaseUrl"; public static final String PARAMETER_REGISTRYBASEURL = "registryBaseUrl";
public static final String PARAMETER_AGENCY = "agency"; public static final String PARAMETER_AGENCY = "agency";
public static final String PARAMETER_VERSION = "version"; public static final String PARAMETER_VERSION = "version";
public static final String PARAMETER_OBSVALUECOLUMN = "obsValueColumn";
public static final String PARAMETER_DATA_TYPE = "dataType"; public static final String PARAMETER_DATA_TYPE = "dataType";
public static final String PARAMETER_TARGET_DATA_TYPE = "targetDataType"; public static final String PARAMETER_TARGET_DATA_TYPE = "targetDataType";

View File

@ -8,79 +8,112 @@ import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.source.Source; import org.gcube.portlets.user.td.gwtservice.shared.source.Source;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.TableType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi" <a
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class SDMXExportSession implements Serializable { public class SDMXExportSession implements Serializable {
private static final long serialVersionUID = 4176034045408445284L; private static final long serialVersionUID = 4176034045408445284L;
protected TabResource tabResource; private TabResource tabResource;
protected Agencies agency; private Agencies agency;
protected Source source; private Source source;
private TableType exportType;
protected String id;
protected String agencyName; private String id;
protected String version; private String agencyName;
protected String registryBaseUrl; private String version;
private String registryBaseUrl;
private ColumnData obsValueColumn;
public TabResource getTabResource() { public TabResource getTabResource() {
return tabResource; return tabResource;
} }
public void setTabResource(TabResource tabResource) { public void setTabResource(TabResource tabResource) {
this.tabResource = tabResource; this.tabResource = tabResource;
} }
public Agencies getAgency() { public Agencies getAgency() {
return agency; return agency;
} }
public void setAgency(Agencies agency) { public void setAgency(Agencies agency) {
this.agency = agency; this.agency = agency;
} }
public Source getSource() { public Source getSource() {
return source; return source;
} }
public void setSource(Source source) { public void setSource(Source source) {
this.source = source; this.source = source;
} }
public String getId() { public String getId() {
return id; return id;
} }
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getAgencyName() { public String getAgencyName() {
return agencyName; return agencyName;
} }
public void setAgencyName(String agencyName) { public void setAgencyName(String agencyName) {
this.agencyName = agencyName; this.agencyName = agencyName;
} }
public String getVersion() { public String getVersion() {
return version; return version;
} }
public void setVersion(String version) { public void setVersion(String version) {
this.version = version; this.version = version;
} }
public String getRegistryBaseUrl() { public String getRegistryBaseUrl() {
return registryBaseUrl; return registryBaseUrl;
} }
public void setRegistryBaseUrl(String registryBaseUrl) { public void setRegistryBaseUrl(String registryBaseUrl) {
this.registryBaseUrl = registryBaseUrl; this.registryBaseUrl = registryBaseUrl;
} }
public TableType getExportType() {
return exportType;
}
public void setExportType(TableType exportType) {
this.exportType = exportType;
}
public ColumnData getObsValueColumn() {
return obsValueColumn;
}
public void setObsValueColumn(ColumnData obsValueColumn) {
this.obsValueColumn = obsValueColumn;
}
@Override @Override
public String toString() { public String toString() {
return "SDMXExportSession [tabResource=" + tabResource + ", agency=" return "SDMXExportSession [tabResource=" + tabResource + ", agency="
+ agency + ", source=" + source + ", id=" + id + agency + ", source=" + source + ", exportType=" + exportType
+ ", agencyName=" + agencyName + ", version=" + version + ", id=" + id + ", agencyName=" + agencyName + ", version="
+ ", registryBaseUrl=" + registryBaseUrl + "]"; + version + ", registryBaseUrl=" + registryBaseUrl
+ ", obsValueColumn=" + obsValueColumn + "]";
} }
} }

View File

@ -15,10 +15,10 @@ public class Agencies implements Serializable {
private static final long serialVersionUID = -8353499109124097114L; private static final long serialVersionUID = -8353499109124097114L;
protected String id; private String id;
protected String name; private String name;
protected String description; private String description;
protected String nameLabel; private String nameLabel;
public Agencies(){} public Agencies(){}