Giancarlo Panichi 2017-02-01 16:06:09 +00:00 committed by Giancarlo Panichi
commit b9b698b6fc
30 changed files with 2451 additions and 0 deletions

37
.classpath Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/tabular-data-widgetx-tdx-source-1.9.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/tabular-data-widgetx-tdx-source-1.9.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/tabular-data-widgetx-tdx-source-1.9.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

36
.project Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tabular-data-widgetx-tdx-source</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="tabular-data-widgetx-tdx-source">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.7"/>
</faceted-project>

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

1
distro/LICENSE Normal file
View File

@ -0,0 +1 @@
${gcube.license}

68
distro/README Normal file
View File

@ -0,0 +1,68 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
Maintainers
-----------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
https://gcube.wiki.gcube-system.org/gcube/index.php/Tabular_Data_Manager
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
https://gcube.wiki.gcube-system.org/gcube/index.php/Tabular_Data_Manager
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

40
distro/changelog.xml Normal file
View File

@ -0,0 +1,40 @@
<ReleaseNotes>
<Changeset component="${groupId}.${artifactId}.1-10-0" date="2017-02-15">
<Change>Updated to new PortalContext [ticket #6548]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-9-0" date="2016-12-01">
<Change>Added fix for support new portal theme</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-8-0" date="2015-07-03">
<Change>Added different colors for columns of different type [issue #251]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-7-0" date="2015-04-30">
<Change>Updated in line filter to suppurt soundex, text begin and text
end</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-6-0" date="2015-01-31">
<Change>Added column ordering</Change>
<Change>Updated in line filter</Change>
<Change>Updated numeric type to double</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-0" date="2014-10-31">
<Change>Updated pom dependencies</Change>
<Change>Updated Geometry type support</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-4-0" date="2014-09-12">
<Change>Updated grid behavior</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-3-0" date="2014-07-04">
<Change>Updated grid, now shows single view column</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-2-0" date="2014-06-05">
<Change>Added Inline Filter</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-1-0" date="2014-04-04">
<Change>Added ColumnDefinitionBuilder</Change>
<Change>Fixed QueryOrder</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-0-0" date="2014-02-01">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

32
distro/descriptor.xml Normal file
View File

@ -0,0 +1,32 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

29
distro/profile.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${project.description}</Description>
<Class>PortletsUser</Class>
<Name>${project.name}</Name>
<Version>${version}</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.name}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>library</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

175
pom.xml Normal file
View File

@ -0,0 +1,175 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<!-- POM file generated with GWT webAppCreator -->
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widgetx-tdx-source</artifactId>
<version>1.9.0-SNAPSHOT</version>
<name>tabular-data-widgetx-tdx-source</name>
<description>tabular-data-widgetx-tdx-source allows access to tabular data service</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx-tdx-source</url>
</scm>
<developers>
<developer>
<name>Giancarlo Panichi</name>
<email>g.panichi@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.1</gwtVersion>
<KEYS>${env.KEYS}</KEYS>
<!-- GWT needs at least java 1.5 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>localRun</id>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<!-- tabular-data-widgetx -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widgetx</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- tabular-data-widget-common-event -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widget-common-event</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- Service Client -->
<dependency>
<groupId>org.gcube.data.analysis.tabulardata</groupId>
<artifactId>service-client-impl</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<!-- TODO check if needed -->
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -0,0 +1,11 @@
package org.gcube.portlets.user.tdwx.datasource.td;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class Constants {
public static final String TDX_DATASOURCE_FACTORY_ID = "TDXDataSourceFactory";
}

View File

@ -0,0 +1,648 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.datasource.td;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import org.gcube.data.analysis.tabulardata.commons.webservice.exception.NoSuchTableException;
import org.gcube.data.analysis.tabulardata.model.column.Column;
import org.gcube.data.analysis.tabulardata.model.metadata.common.TableDescriptorMetadata;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryFilter;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryOrder;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryOrderDirection;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryPage;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData;
import org.gcube.portlets.user.tdwx.datasource.td.filters.FiltersBuilder;
import org.gcube.portlets.user.tdwx.datasource.td.map.ColumnDefinitionBuilder;
import org.gcube.portlets.user.tdwx.datasource.td.trservice.TRService;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.datasource.Direction;
import org.gcube.portlets.user.tdwx.server.datasource.util.TableJSonBuilder;
import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId;
import org.gcube.portlets.user.tdwx.shared.model.ValueType;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDXDataSource implements DataSourceX {
private static final int PAGINGDIMENSION = 300;
private static final String PRIMARY_KEY_COLUMN = "id";
private static final String JSON_ROWS_FIELD = "ROWS";
private static final String JSON_TOTAL_LENGTH_FIELD = "total";
private static final String JSON_OFFSET_FIELD = "offset";
private Logger logger = LoggerFactory.getLogger(TDXDataSource.class);
private String dataSourceFactoryId;
private String tableName;
private TableDefinition tableDefinition;
private int tableSize = -1;
private TableJSonBuilder jsonBuilder;
private TabularDataService service;
private org.gcube.data.analysis.tabulardata.model.table.TableId serviceTableId;
private org.gcube.data.analysis.tabulardata.model.table.Table serviceTable;
private long serviceTabularResourceId;
private TRService trService;
private long tableId;
/**
*
* @param dataSourceFactoryId
* @param tableName
* @return
*/
public static TDXDataSource createTDDataSource(String dataSourceFactoryId,
ServiceCredentials serviceCredentials, String tableName)
throws DataSourceXException {
TDXDataSource dataSource = new TDXDataSource(dataSourceFactoryId,
serviceCredentials, tableName);
return dataSource;
}
/**
*
* @param dataSourceFactoryId
* @param tableIdentifier
* @throws DataSourceXException
*/
public TDXDataSource(String dataSourceFactoryId, ServiceCredentials serviceCredentials,
String tableIdentifier) throws DataSourceXException {
if (dataSourceFactoryId == null) {
logger.error("An error occurred, dataSourceFactoryId is null");
throw new DataSourceXException(
"An error occurred, dataSourceFactoryId is null");
}
if (tableIdentifier == null) {
logger.error("An error occurred, tableName is null");
throw new DataSourceXException(
"An error occurred, tableName is null");
}
this.dataSourceFactoryId = dataSourceFactoryId;
this.tableName = tableIdentifier;
service = TabularDataServiceFactory.getService();
try {
tableId = Long.parseLong(tableIdentifier);
} catch (NumberFormatException e) {
logger.error("An error occurred, tableName is not a long", e);
throw new DataSourceXException(
"An error occurred, no tableName is not a long", e);
}
serviceTableId = new org.gcube.data.analysis.tabulardata.model.table.TableId(
tableId);
try {
serviceTable = service.getTable(serviceTableId);
} catch (NoSuchTableException e) {
logger.error("An error occurred, no such table", e);
throw new DataSourceXException("An error occurred, no such table",
e);
}
// logger.debug("Service Table: " + serviceTable);
TableDescriptorMetadata tableDesc = null;
if (serviceTable.contains(TableDescriptorMetadata.class)) {
tableDesc = serviceTable.getMetadata(TableDescriptorMetadata.class);
if (tableDesc.getRefId() == 0) {
logger.error("Error refId=0 for Table:" + serviceTable);
throw new DataSourceXException(
"Error no valid tabular resource associated with the table:"
+ serviceTable.getId());
} else {
logger.debug("Table " + serviceTable.getId()
+ " connect to tabular resource: "
+ tableDesc.getRefId());
serviceTabularResourceId = tableDesc.getRefId();
}
} else {
logger.debug("No TableDescriptorMetadata found (Supposed Time Table):"
+ tableId);
/*
* TIME TABLE hasn't tabular resource connected
*/
/*
* throw new DataSourceXException(
* "Error no valid tabular resource associated with the table:" +
* serviceTable.getId());
*/
}
trService = new TRService();
trService.setService(service);
TabularResourceId tabularResourceId = new TabularResourceId(
serviceTabularResourceId);
trService.setTabularResourceId(tabularResourceId);
}
@Override
public String getDataSourceFactoryId() {
return dataSourceFactoryId;
}
@Override
public TableDefinition getTableDefinition() throws DataSourceXException {
logger.debug("Retrieving table definition");
tableDefinition = extractTableDefinition();
return tableDefinition;
}
/**
*
* @return
* @throws DataSourceXException
*/
protected TableDefinition extractTableDefinition()
throws DataSourceXException {
List<ColumnDefinition> columns = getColumnDefinitions();
logger.debug("Creating tableId...");
TableId id = new TableId(dataSourceFactoryId, tableName);
TableDefinition tableDefinition = new TableDefinition(id, tableName,
JSON_ROWS_FIELD, JSON_TOTAL_LENGTH_FIELD, JSON_OFFSET_FIELD,
columns);
tableDefinition.setModelKeyColumnId(PRIMARY_KEY_COLUMN);
logger.debug("TableDefinition Created");
return tableDefinition;
}
protected List<ColumnDefinition> getColumnDefinitions()
throws DataSourceXException {
logger.debug("Creating list of columns definition...");
List<Column> serviceListColumn = serviceTable.getColumns();
ArrayList<ColumnDefinition> columns = new ArrayList<ColumnDefinition>();
ArrayList<ColumnDefinition> dimensions = new ArrayList<ColumnDefinition>();
Column serviceColumn;
for (int i = 0; i < serviceListColumn.size(); i++) {
serviceColumn = serviceListColumn.get(i);
ColumnDefinition column = getColumnDefinition(serviceColumn, i);
columns.add(column);
if (column.getType() == ColumnType.DIMENSION
|| column.getType() == ColumnType.TIMEDIMENSION) {
dimensions.add(column);
}
}
for (int i = 0; i < dimensions.size(); i++) {
ColumnDefinition dim = dimensions.get(i);
RelationshipData rel = dim.getRelationshipData();
if (rel != null) {
String cId = rel.getTargetColumnId();
if (cId != null) {
for (int j = 0; j < columns.size(); j++) {
ColumnDefinition c = columns.get(j);
if (c.getColumnLocalId() != null
&& (c.getType() == ColumnType.VIEWCOLUMN_OF_DIMENSION || c
.getType() == ColumnType.VIEWCOLUMN_OF_TIMEDIMENSION)
&& c.getColumnLocalId().compareTo(cId) == 0) {
c.setVisible(true);
columns.set(j, c);
break;
}
}
}
}
}
logger.debug("List of columns definition created");
return columns;
}
protected ColumnDefinition getColumnDefinition(Column serviceColumn,
int ordinalPosition) throws DataSourceXException {
ColumnDefinitionBuilder columnDefinitionBuilder = new ColumnDefinitionBuilder(
service, serviceTable, serviceColumn, ordinalPosition);
ColumnDefinition columnDefinition = columnDefinitionBuilder.build();
/* logger.debug("Column Definition:" + columnDefinition); */
return columnDefinition;
}
protected ColumnDefinition createPrimaryKeyColumn(
List<ColumnDefinition> columns) {
List<String> ids = new ArrayList<String>(columns.size());
for (ColumnDefinition column : columns)
ids.add(column.getId());
String id = PRIMARY_KEY_COLUMN;
for (int i = 0; ids.contains(id); id = PRIMARY_KEY_COLUMN + i++)
;
return new ColumnDefinition(id, id, id, ValueType.INTEGER, -1, false,
false,
org.gcube.portlets.user.tdwx.shared.model.ColumnType.SYSTEM);
}
protected void retrieveTableSize(int start, int limit,
QueryFilter queryFilter) throws DataSourceXException {
tableSize = 0;
try {
tableSize = service.getQueryLenght(serviceTableId, queryFilter);
} catch (NoSuchTableException e) {
logger.error("An error occurred, tableSize is not recovered", e);
throw new DataSourceXException(
"An error occurred, tableSize is not recovered", e);
}
start = Math.max(0, start);
start = Math.min(start, tableSize);
if (start + limit > tableSize)
limit = tableSize - start;
logger.debug("checked bounds start: " + start + " limit: " + limit);
}
// Request from user
@Override
public String getDataAsJSon(int start, int limit, String sortingColumn,
Direction direction, ArrayList<FilterInformation> filters,
ArrayList<StaticFilterInformation> staticFilters)
throws DataSourceXException {
logger.debug("getDataAsJSon start: " + start + " limit: " + limit
+ " sortingColumn: " + sortingColumn + " direction: "
+ direction + " filters:" + filters.size() + " staticFilters:"
+ staticFilters.size());
TableDefinition tableDefinition = getTableDefinition();
logger.debug("Creating queryOrder...");
QueryOrder queryOrder = null;
if (sortingColumn != null) {
if (tableDefinition.getColumns().get(sortingColumn) == null) {
logger.error("The specified sorting column \"" + sortingColumn
+ "\" don't exists");
throw new DataSourceXException(
"The specified sorting column \"" + sortingColumn
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(sortingColumn);
Column column = serviceTable.getColumnByName(columnDefinition
.getId());
switch (direction) {
case ASC:
queryOrder = new QueryOrder(column.getLocalId(),
QueryOrderDirection.ASCENDING);
break;
case DESC:
queryOrder = new QueryOrder(column.getLocalId(),
QueryOrderDirection.DESCENDING);
break;
default:
break;
}
}
} else {
if (tableDefinition.getColumns().get(PRIMARY_KEY_COLUMN) == null) {
logger.error("The primary key column \"" + PRIMARY_KEY_COLUMN
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(PRIMARY_KEY_COLUMN);
Column column = serviceTable.getColumnByName(columnDefinition
.getId());
queryOrder = new QueryOrder(column.getLocalId(),
QueryOrderDirection.ASCENDING);
}
}
QueryFilter queryFilter = null;
if ((filters != null && filters.size() > 0)
|| (staticFilters != null && staticFilters.size() > 0)) {
FiltersBuilder filtersBuilder = new FiltersBuilder(filters,
staticFilters, tableDefinition, serviceTable);
queryFilter = filtersBuilder.createQueryFilter();
}
retrieveTableSize(start, limit, queryFilter);
String json = getJSon(start, queryOrder, queryFilter);
logger.trace("Returning json");
// logger.debug(json);
return json;
}
protected ArrayList<ColumnDefinition> sort(
Collection<ColumnDefinition> columns) {
ArrayList<ColumnDefinition> lcolumns = new ArrayList<ColumnDefinition>();
for (ColumnDefinition column : columns) {
lcolumns.add(column);
}
Collections.sort(lcolumns, new Comparator<ColumnDefinition>() {
@Override
public int compare(ColumnDefinition cd1, ColumnDefinition cd2) {
int comp = 0;
if (cd1.getPosition() == cd2.getPosition()) {
comp = 0;
} else {
if (cd1.getPosition() > cd2.getPosition()) {
comp = 1;
} else {
comp = -1;
}
}
return comp;
}
});
return lcolumns;
}
protected String getJSon(int start, QueryOrder queryOrder,
QueryFilter queryFilter) throws DataSourceXException {
logger.debug("Retrieving JSon");
logger.debug("[" + queryOrder + ", " + queryFilter + "]");
TableDefinition tableDefinition = getTableDefinition();
logger.debug("Retrieved table definition");
Collection<ColumnDefinition> columns = tableDefinition.getColumns()
.values();
logger.debug("Retrieved Columns");
ArrayList<ColumnDefinition> lcolumns = sort(columns);
// logger.debug("ColumnDefinition:\n" + lcolumns.toString());
QueryPage queryPage = new QueryPage(start, PAGINGDIMENSION);
logger.debug("Created queryPage");
String serviceJson = null;
try {
if (queryOrder == null && queryFilter == null) {
serviceJson = service.queryAsJson(serviceTableId, queryPage);
} else {
if (queryOrder == null && queryFilter != null) {
serviceJson = service.queryAsJson(serviceTableId,
queryPage, queryFilter);
} else {
if (queryOrder != null && queryFilter == null) {
serviceJson = service.queryAsJson(serviceTableId,
queryPage, queryOrder);
} else {
if (queryOrder != null && queryFilter != null) {
logger.debug("Order & Filter: " + queryOrder + " "
+ queryFilter);
serviceJson = service.queryAsJson(serviceTableId,
queryPage, queryFilter, queryOrder);
} else {
logger.debug("No queryAsJson valid");
}
}
}
}
} catch (NoSuchTableException e) {
logger.error("An error occurred, no such table", e);
throw new DataSourceXException("An error occurred, no such table",
e);
} catch (Throwable e) {
logger.error("An error occurred", e);
throw new DataSourceXException("An error occurred", e);
}
logger.debug("Created serviceJson");
// logger.debug(serviceJson);
return createJson(start, serviceJson, lcolumns);
}
protected String createJson(int start, String serviceJson,
ArrayList<ColumnDefinition> lcolumns) throws DataSourceXException {
TableJSonBuilder json = getBuilder();
json.startRows();
int id = start;
JSONArray currentRow = null;
int i = -1;
int j = -1;
int totalRows = -1;
String s = null;
try {
org.json.JSONObject obj = new org.json.JSONObject(serviceJson);
org.json.JSONArray rows = obj.getJSONArray("rows");
totalRows = rows.length();
logger.debug("Reading rows from json");
for (i = 0; i < totalRows; i++) {
json.startRow();
currentRow = rows.getJSONArray(i);
j = 0;
for (ColumnDefinition column : lcolumns) {
String columnId = column.getId();
if (currentRow.isNull(j)) {
json.addValue(columnId, "");
} else {
switch (column.getValueType()) {
case DATE:
Long day = currentRow.getLong(j);
Date dd = new Date();
dd.setTime(day);
json.addValue(columnId, day);
break;
case BOOLEAN:
Boolean b = currentRow.getBoolean(j);
json.addValue(columnId, b);
break;
case DOUBLE:
Double d = currentRow.getDouble(j);
json.addValue(columnId, d);
break;
case INTEGER:
int integ = currentRow.getInt(j);
json.addValue(columnId, integ);
break;
case LONG:
Long l = currentRow.getLong(j);
json.addValue(columnId, l);
break;
case STRING:
s = currentRow.getString(j);
json.addValue(columnId, s);
break;
case GEOMETRY:
s = currentRow.getString(j);
json.addValue(columnId, s);
break;
default:
logger.warn("Unknow value type "
+ column.getValueType());
}
}
j++;
}
json.endRow();
}
id += i;
} catch (JSONException e) {
logger.error("An error occurred while parsing json document\n"
+ "At Row " + i + ",Column " + j + "\nRow Content: "
+ currentRow + "\nLenght rows " + totalRows, e);
throw new DataSourceXException(
"An error occurred, while reading json of service", e);
}
json.endRows();
json.setTotalLength(tableSize);
json.setOffset(start);
json.close();
logger.trace("produced " + (id - start) + " rows");
return json.toString();
}
protected TableJSonBuilder getBuilder() throws DataSourceXException {
try {
if (jsonBuilder == null) {
TableDefinition tdef = getTableDefinition();
logger.debug("Creating jsonBuilder...");
if (tdef != null) {
jsonBuilder = new TableJSonBuilder(tdef);
} else {
logger.error("table definition is null");
throw new DataSourceXException("table definition is null");
}
} else {
jsonBuilder.clean();
}
return jsonBuilder;
} catch (Exception e) {
logger.debug("Error Creating jsonBuilder: " + e.getMessage());
throw new DataSourceXException("Error Creating jsonBuilder: "
+ e.getMessage());
}
}
protected int getTableSize() throws DataSourceXException {
return tableSize;
}
public void close() {
// The service is stateless there is no need to close
}
@Override
public TableDefinition setColumnReordering(
ColumnsReorderingConfig columnsReorderingConfig)
throws DataSourceXException {
logger.debug("SetColumnReordering: " + columnsReorderingConfig);
trService.startChangeSingleColumnPosition(columnsReorderingConfig);
updateTableAfterOperation();
logger.debug("Retrieving table definition");
tableDefinition = extractTableDefinition();
return tableDefinition;
}
protected void updateTableAfterOperation() throws DataSourceXException {
serviceTableId = new org.gcube.data.analysis.tabulardata.model.table.TableId(
tableId);
try {
serviceTable = service.getTable(serviceTableId);
} catch (NoSuchTableException e) {
logger.error("An error occurred, no such table", e);
throw new DataSourceXException("An error occurred, no such table",
e);
}
// logger.debug("Service Table: " + serviceTable);
TableDescriptorMetadata tableDesc = null;
if (serviceTable.contains(TableDescriptorMetadata.class)) {
tableDesc = serviceTable.getMetadata(TableDescriptorMetadata.class);
if (tableDesc.getRefId() == 0) {
logger.debug("Error refId=0 for Table:" + serviceTable);
throw new DataSourceXException(
"Error no valid tabular resource associated with the table:"
+ serviceTable.getId());
} else {
logger.debug("Table " + serviceTable.getId()
+ " connect to tabular resource: "
+ tableDesc.getRefId());
serviceTabularResourceId = tableDesc.getRefId();
}
} else {
logger.debug("No TableDescriptorMetadata found (Supposed Time Table):"
+ tableId);
/*
* TIME TABLE hasn't tabular resource connected
*/
/*
* throw new DataSourceXException(
* "Error no valid tabular resource associated with the table:" +
* serviceTable.getId());
*/
}
trService.setService(service);
TabularResourceId tabularResourceId = new TabularResourceId(
serviceTabularResourceId);
trService.setTabularResourceId(tabularResourceId);
}
@Override
public String toString() {
return "TDXDataSource [serviceTabularResourceId="
+ serviceTabularResourceId + ", serviceTableId="
+ serviceTableId + "]";
}
}

View File

@ -0,0 +1,54 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.datasource.td;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactory;
import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.model.TableId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDXDataSourceFactory implements DataSourceXFactory {
private Logger logger = LoggerFactory.getLogger(TDXDataSourceFactory.class);
private static final String ID=Constants.TDX_DATASOURCE_FACTORY_ID;
/**
* {@inheritDoc}
*/
public String getId() {
return ID;
}
/**
* {@inheritDoc}
*/
public DataSourceX openDataSource(ServiceCredentials serviceCredentials, TableId tableId) throws DataSourceXException {
logger.debug("openDataSource: "+tableId);
String table = tableId.getTableKey();
TDXDataSource dataSource = new TDXDataSource(ID,serviceCredentials,table);
return dataSource;
}
/**
* {@inheritDoc}
*/
public void closeDataSource(ServiceCredentials serviceCredentials, DataSourceX dataSource) throws DataSourceXException {
logger.debug("closeDataSource: "+dataSource);
((TDXDataSource)dataSource).close();
}
}

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.user.tdwx.datasource.td.exception;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OperationException extends DataSourceXException {
private static final long serialVersionUID = -8593898774262390757L;
/**
*
* @param message
*/
public OperationException(String message) {
super(message);
}
/**
* @param message
* @param cause
*/
public OperationException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,490 @@
package org.gcube.portlets.user.tdwx.datasource.td.filters;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.Equals;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.GreaterThan;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.LessThan;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Soundex;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextBeginsWith;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextContains;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextEndsWith;
import org.gcube.data.analysis.tabulardata.expression.logical.And;
import org.gcube.data.analysis.tabulardata.model.column.Column;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.column.ColumnReference;
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDBoolean;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDDate;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDInteger;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDNumeric;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDText;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryFilter;
import org.gcube.portlets.user.tdwx.datasource.td.TDXDataSource;
import org.gcube.portlets.user.tdwx.datasource.td.map.DataTypeMap;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.ValueType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FiltersBuilder {
protected ArrayList<FilterInformation> filters;
protected ArrayList<StaticFilterInformation> staticFilters;
protected TableDefinition tableDefinition;
protected Table serviceTable;
protected Logger logger = LoggerFactory.getLogger(TDXDataSource.class);
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/**
*
* @param filters
* @param tableDefinition
*/
public FiltersBuilder(ArrayList<FilterInformation> filters,
ArrayList<StaticFilterInformation> staticFilters,
TableDefinition tableDefinition, Table serviceTable) {
this.filters = filters;
this.staticFilters = staticFilters;
this.tableDefinition = tableDefinition;
this.serviceTable = serviceTable;
}
/**
*
* @return
* @throws DataSourceXException
*/
protected Expression createExpression() throws DataSourceXException {
try {
Expression exp = null;
ArrayList<Expression> andExp = new ArrayList<Expression>();
if (filters != null) {
for (FilterInformation filter : filters) {
switch (filter.getFilterType()) {
case "string":
if (tableDefinition.getColumns().get(
filter.getFilterField()) == null) {
logger.error("The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
throw new DataSourceXException(
"The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(filter.getFilterField());
Column column = serviceTable
.getColumnByName(columnDefinition.getId());
Expression ex = getExpressionText(column, filter);
if (ex != null) {
andExp.add(ex);
}
}
break;
case "numeric":
if (tableDefinition.getColumns().get(
filter.getFilterField()) == null) {
logger.error("The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
throw new DataSourceXException(
"The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(filter.getFilterField());
Column column = serviceTable
.getColumnByName(columnDefinition.getId());
Expression ex = getExpressionNumeric(column, filter);
if (ex != null) {
andExp.add(ex);
}
}
break;
case "boolean":
if (tableDefinition.getColumns().get(
filter.getFilterField()) == null) {
logger.error("The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
throw new DataSourceXException(
"The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(filter.getFilterField());
Column column = serviceTable
.getColumnByName(columnDefinition.getId());
Equals contains = new Equals(new ColumnReference(
serviceTable.getId(), column.getLocalId()),
new TDBoolean(new Boolean(filter
.getFilterValue())));
andExp.add(contains);
}
break;
case "date":
if (tableDefinition.getColumns().get(
filter.getFilterField()) == null) {
logger.error("The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
throw new DataSourceXException(
"The specified filter column \""
+ filter.getFilterField()
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(filter.getFilterField());
Column column = serviceTable
.getColumnByName(columnDefinition.getId());
Expression ex = getExpressionDate(column, filter);
if (ex != null) {
andExp.add(ex);
}
}
break;
default:
break;
}
}
}
if (staticFilters != null) {
for (StaticFilterInformation staticFilter : staticFilters) {
if (tableDefinition.getColumns().get(
staticFilter.getColumnName()) == null) {
logger.error("Static Filter not applicable, the specified column \""
+ staticFilter.getColumnName()
+ "\" don't exists");
throw new DataSourceXException(
"Static Filter not applicable, the specified column \""
+ staticFilter.getColumnName()
+ "\" don't exists");
} else {
ColumnDefinition columnDefinition = tableDefinition
.getColumns().get(staticFilter.getColumnName());
Column column = serviceTable
.getColumnById(new ColumnLocalId(
columnDefinition.getColumnLocalId()));
Expression e = createStaticExpression(staticFilter,
serviceTable.getId(), column);
if (e != null) {
andExp.add(e);
}
}
}
}
if (andExp.size() > 0) {
if (andExp.size() == 1) {
exp = andExp.get(0);
} else {
And andE = new And(andExp);
exp = andE;
}
}
logger.debug("Filter Expression created: " + exp);
return exp;
} catch (Throwable e) {
logger.error("Create expression failed. " + e.getLocalizedMessage());
e.printStackTrace();
throw new DataSourceXException("Create expression failed. "
+ e.getLocalizedMessage());
}
}
private Expression createStaticExpression(
StaticFilterInformation staticFilter, TableId id, Column column)
throws DataSourceXException {
try {
Expression exp = null;
DataType dataType = column.getDataType();
ValueType valueType = DataTypeMap.getValueType(dataType);
switch (valueType) {
case BOOLEAN:
TDBoolean bool = new TDBoolean(new Boolean(
staticFilter.getFilterValue()));
exp = new Equals(new ColumnReference(id, column.getLocalId()),
bool);
break;
case DATE:
try {
Date dd = sdf.parse(staticFilter.getFilterValue());
TDDate tdDate = new TDDate(dd);
exp = new Equals(new ColumnReference(id,
column.getLocalId()), tdDate);
} catch (ParseException e) {
logger.error("Static Filter has not valid value type: "
+ staticFilter);
e.printStackTrace();
}
break;
case DOUBLE:
TDNumeric doublenum = new TDNumeric(new Double(
staticFilter.getFilterValue()));
exp = new Equals(new ColumnReference(id, column.getLocalId()),
doublenum);
break;
case INTEGER:
TDInteger intnum = new TDInteger(new Integer(
staticFilter.getFilterValue()));
exp = new Equals(new ColumnReference(id, column.getLocalId()),
intnum);
break;
case LONG:
TDInteger longnum = new TDInteger(new Integer(
staticFilter.getFilterValue()));
exp = new Equals(new ColumnReference(id, column.getLocalId()),
longnum);
break;
case STRING:
exp = new TextContains(new ColumnReference(id,
column.getLocalId()), new TDText(
staticFilter.getFilterValue()));
break;
case GEOMETRY:
exp = new TextContains(new ColumnReference(id,
column.getLocalId()), new TDText(
staticFilter.getFilterValue()));
break;
default:
break;
}
return exp;
} catch (Throwable e) {
logger.error("Create Static Filter expression failed :"
+ e.getLocalizedMessage());
e.printStackTrace();
throw new DataSourceXException(
"Create Static Filter expression failed :"
+ e.getLocalizedMessage());
}
}
protected Expression getExpressionDate(Column column,
FilterInformation filter) throws DataSourceXException {
// [{ "filterField":"kqljyp" ,"filterType":"date"
// ,"filterComparison":"on" ,"filterValue": "1399370400000" }]
Expression exp = null;
Date dd = new Date();
Long day = null;
try {
day = new Long(filter.getFilterValue());
} catch (NumberFormatException e) {
logger.error("No valid filterValue for date: "
+ filter.getFilterValue());
throw new DataSourceXException("No valid filter value");
}
dd.setTime(day);
TDDate tdDate = new TDDate(dd);
switch (filter.getFilterComparison()) {
case "on":
exp = new Equals(new ColumnReference(serviceTable.getId(),
column.getLocalId()), tdDate);
break;
case "after":
exp = new GreaterThan(new ColumnReference(serviceTable.getId(),
column.getLocalId()), tdDate);
break;
case "before":
exp = new LessThan(new ColumnReference(serviceTable.getId(),
column.getLocalId()), tdDate);
break;
default:
break;
}
return exp;
}
protected Expression getExpressionText(Column column,
FilterInformation filter) {
Expression exp = null;
String comparison=filter.getFilterComparison();
if(comparison!=null&& comparison.isEmpty()){
return exp;
}
switch(comparison){
case "contains":
TextContains contains = new TextContains(
new ColumnReference(serviceTable.getId(),
column.getLocalId()), new TDText(
filter.getFilterValue()));
exp=contains;
break;
case "begins":
TextBeginsWith begins = new TextBeginsWith(
new ColumnReference(serviceTable.getId(),
column.getLocalId()), new TDText(
filter.getFilterValue()));
exp=begins;
break;
case "ends":
TextEndsWith ends = new TextEndsWith(
new ColumnReference(serviceTable.getId(),
column.getLocalId()), new TDText(
filter.getFilterValue()));
exp=ends;
break;
case "soundex":
Soundex soundexCol= new Soundex(new ColumnReference(serviceTable.getId(),
column.getLocalId()));
Soundex soundexVal= new Soundex(new TDText(
filter.getFilterValue()));
Equals eq=new Equals(soundexCol, soundexVal);
exp=eq;
default:
break;
}
return exp;
}
protected Expression getExpressionNumeric(Column column,
FilterInformation filter) {
Expression exp = null;
ValueType vt = DataTypeMap.getValueType(column.getDataType());
switch (vt) {
case DOUBLE:
TDNumeric floatnum = new TDNumeric(new Double(
filter.getFilterValue()));
if (filter.getFilterComparison().compareTo("eq") == 0) {
exp = new Equals(new ColumnReference(serviceTable.getId(),
column.getLocalId()), floatnum);
} else {
if (filter.getFilterComparison().compareTo("gt") == 0) {
exp = new GreaterThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()),
floatnum);
} else {
if (filter.getFilterComparison().compareTo("lt") == 0) {
exp = new LessThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()),
floatnum);
} else {
}
}
}
break;
case INTEGER:
TDInteger intnum = new TDInteger(new Integer(
filter.getFilterValue()));
if (filter.getFilterComparison().compareTo("eq") == 0) {
exp = new Equals(new ColumnReference(serviceTable.getId(),
column.getLocalId()), intnum);
} else {
if (filter.getFilterComparison().compareTo("gt") == 0) {
exp = new GreaterThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()), intnum);
} else {
if (filter.getFilterComparison().compareTo("lt") == 0) {
exp = new LessThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()),
intnum);
} else {
}
}
}
break;
case LONG:
TDInteger longnum = new TDInteger(new Integer(
filter.getFilterValue()));
if (filter.getFilterComparison().compareTo("eq") == 0) {
exp = new Equals(new ColumnReference(serviceTable.getId(),
column.getLocalId()), longnum);
} else {
if (filter.getFilterComparison().compareTo("gt") == 0) {
exp = new GreaterThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()), longnum);
} else {
if (filter.getFilterComparison().compareTo("lt") == 0) {
exp = new LessThan(new ColumnReference(
serviceTable.getId(), column.getLocalId()),
longnum);
} else {
}
}
}
break;
default:
break;
}
return exp;
}
/**
*
* @return
* @throws DataSourceXException
*/
public QueryFilter createQueryFilter() throws DataSourceXException {
QueryFilter queryFilter = null;
Expression exp = createExpression();
if (exp != null) {
queryFilter = new QueryFilter(exp);
}
logger.debug("QueryFilter: " + queryFilter);
return queryFilter;
}
}

View File

@ -0,0 +1,336 @@
package org.gcube.portlets.user.tdwx.datasource.td.map;
import java.util.List;
import org.gcube.data.analysis.tabulardata.metadata.NoSuchMetadataException;
import org.gcube.data.analysis.tabulardata.model.column.Column;
import org.gcube.data.analysis.tabulardata.model.column.ColumnType;
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
import org.gcube.data.analysis.tabulardata.model.metadata.column.DataLocaleMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.column.PeriodTypeMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.column.ValidationReferencesMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.column.ViewColumnMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.common.LocalizedText;
import org.gcube.data.analysis.tabulardata.model.metadata.common.NamesMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.common.Validation;
import org.gcube.data.analysis.tabulardata.model.metadata.common.ValidationsMetadata;
import org.gcube.data.analysis.tabulardata.model.relationship.ColumnRelationship;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.time.PeriodType;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ColumnDefinitionBuilder {
private static final String PRIMARY_KEY_COLUMN = "id";
private Logger logger = LoggerFactory
.getLogger(ColumnDefinitionBuilder.class);
private TabularDataService service;
private Table serviceTable;
private Column serviceColumn;
private String tooltipMessage;
private String columnName;
private String columnLocalId;
private boolean visible;
private boolean editable;
private org.gcube.portlets.user.tdwx.shared.model.ColumnType type;
private String columnLabel;
private String locale;
private int ordinalPosition;
private PeriodTypeMetadata periodTypeMetadata;
protected PeriodType periodType;
private RelationshipData relationshipData;
private String sourceTableDimensionColumnId;
private String targetTableColumnId;
private long targetTableId;
private boolean viewColumn;
public ColumnDefinitionBuilder(TabularDataService service,
Table serviceTable, Column serviceColumn, int ordinalPosition)
throws DataSourceXException {
this.service = service;
this.serviceTable = serviceTable;
this.serviceColumn = serviceColumn;
this.ordinalPosition = ordinalPosition;
visible = true;
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.USER;
editable = true;
ColumnType ct = serviceColumn.getColumnType();
if (ColumnTypeMap.isIdColumnType(ct)) {
columnLabel = PRIMARY_KEY_COLUMN;
visible = false;
editable = false;
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.COLUMNID;
} else {
periodTypeMetadata = null;
if (serviceColumn.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = serviceColumn
.getMetadata(PeriodTypeMetadata.class);
periodType = periodTypeMetadata.getType();
}
if (ColumnTypeMap.isValidationColumnType(ct)) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.VALIDATION;
editable = false;
} else {
if (ColumnTypeMap.isTimeDimensionColumnType(ct)) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.TIMEDIMENSION;
visible = false;
retrieveRelationship();
} else {
if (ColumnTypeMap.isDimensionColumnType(ct)) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.DIMENSION;
visible = false;
retrieveRelationship();
} else {
if (ColumnTypeMap.isMeasureColumnType(ct)) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.MEASURE;
} else {
if (ColumnTypeMap.isCodeColumnType(ct)) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.CODE;
}
}
}
}
}
if (serviceColumn.contains(ViewColumnMetadata.class)) {
retrieveViewColumnMetadata();
visible = false;
viewColumn = true;
} else {
viewColumn = false;
}
NamesMetadata labelsMetadata = null;
try {
labelsMetadata = serviceColumn.getMetadata(NamesMetadata.class);
} catch (NoSuchMetadataException e) {
logger.debug("labelMetadata: NoSuchMetadataException "
+ e.getLocalizedMessage());
}
if (labelsMetadata == null) {
columnLabel = "nolabel";
} else {
LocalizedText cl = null;
cl = labelsMetadata.getTextWithLocale("en");
if (cl == null) {
columnLabel = "nolabel";
logger.debug("ColumnLabel no label in en");
} else {
columnLabel = cl.getValue();
if (columnLabel == null || columnLabel.isEmpty()) {
columnLabel = "nolabel";
}
}
}
DataLocaleMetadata dataLocaleMetadata = null;
try {
dataLocaleMetadata = serviceColumn
.getMetadata(DataLocaleMetadata.class);
} catch (NoSuchMetadataException e) {
logger.debug("DataLocaleMetadata: NoSuchMetadataException "
+ e.getLocalizedMessage());
}
if (dataLocaleMetadata == null) {
logger.debug("No DataLocaleMetadata");
locale = "";
} else {
locale = dataLocaleMetadata.getLocale();
}
}
}
private void retrieveViewColumnMetadata() throws DataSourceXException {
ViewColumnMetadata viewMetadata = serviceColumn
.getMetadata(ViewColumnMetadata.class);
// logger.debug("ViewColumnMetadata: " + viewMetadata.toString());
Column sourceColumn = serviceTable.getColumnById(viewMetadata
.getSourceTableDimensionColumnId());
if (sourceColumn.getColumnType().getCode()
.compareTo(ColumnTypeCode.TIMEDIMENSION.toString()) == 0) {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.VIEWCOLUMN_OF_TIMEDIMENSION;
PeriodTypeMetadata periodTypeMetadataSourceColumn = null;
if (sourceColumn.contains(PeriodTypeMetadata.class)) {
periodTypeMetadataSourceColumn = sourceColumn
.getMetadata(PeriodTypeMetadata.class);
Table timeTable = service
.getTimeTable(periodTypeMetadataSourceColumn.getType());
if (timeTable == null || timeTable.getId() == null) {
throw new DataSourceXException(
"Error retrieving Time Table: " + timeTable);
}
// logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable
.getColumnByName(periodTypeMetadataSourceColumn
.getType().getName());
sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue();
targetTableColumnId = timeColumn.getLocalId().getValue();
targetTableId = timeTable.getId().getValue();
} else {
logger.error("Error retrieving Time Table for view column:"
+ serviceColumn
+ " , source column do not have a PeriodTypeMetadata: "
+ sourceColumn);
throw new DataSourceXException(
"Error retrieving Time Table, source column do not have a PeriodTypeMetadata");
}
} else {
type = org.gcube.portlets.user.tdwx.shared.model.ColumnType.VIEWCOLUMN_OF_DIMENSION;
sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue();
targetTableColumnId = viewMetadata.getTargetTableColumnId()
.getValue();
targetTableId = viewMetadata.getTargetTableId().getValue();
}
}
private void retrieveRelationship() throws DataSourceXException {
if (serviceColumn.getColumnType().getCode()
.compareTo(ColumnTypeCode.TIMEDIMENSION.toString()) == 0) {
Table timeTable = service
.getTimeTable(periodTypeMetadata.getType());
if (timeTable == null || timeTable.getId() == null) {
throw new DataSourceXException("Error retrieving Time Table: "
+ timeTable);
}
// logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable.getColumnByName(periodTypeMetadata
.getType().getName());
relationshipData = new RelationshipData(timeTable.getId()
.getValue(), timeColumn.getLocalId().getValue());
} else {
ColumnRelationship rel = serviceColumn.getRelationship();
if (rel != null) {
relationshipData = new RelationshipData(rel.getTargetTableId()
.getValue(), rel.getTargetColumnId().getValue());
} else {
logger.error("No valid relationship for column: "
+ serviceColumn.toString());
throw new DataSourceXException(
"Column has not valid relationship");
}
}
}
public boolean isVisible() {
return visible;
}
public org.gcube.portlets.user.tdwx.shared.model.ColumnType getType() {
return type;
}
public String getColumnLabel() {
return columnLabel;
}
public String getColumnName() {
columnName = serviceColumn.getName();
return columnName;
}
public String getColumnLocalId() {
columnLocalId = serviceColumn.getLocalId().getValue();
return columnLocalId;
}
public ValidationReferencesMetadata getValidationReferencesMetadata() {
ValidationReferencesMetadata refs = null;
try {
refs = serviceColumn
.getMetadata(ValidationReferencesMetadata.class);
} catch (NoSuchMetadataException e) {
logger.debug("ValidationReferencesMetadata: NoSuchMetadataException "
+ e.getLocalizedMessage());
}
return refs;
}
public String getTooltipMessage() {
String valids = new String();
ValidationsMetadata val = null;
try {
val = serviceColumn.getMetadata(ValidationsMetadata.class);
} catch (NoSuchMetadataException e) {
/*
* logger.debug("No validatationsMetadata present: " +
* e.getLocalizedMessage());
*/
}
if (val != null) {
List<Validation> listValidationsMetadata = ((ValidationsMetadata) val)
.getValidations();
for (Validation validation : listValidationsMetadata) {
valids.concat(validation.getDescription() + "\n");
}
}
tooltipMessage = valids;
return tooltipMessage;
}
public ColumnDefinition build() {
ColumnDefinition columnDefinition = new ColumnDefinition(
getColumnName(), getColumnLocalId(), getColumnLabel());
columnDefinition.setLocale(locale);
columnDefinition.setRelationshipData(relationshipData);
columnDefinition.setViewColumn(viewColumn);
columnDefinition.setTargetTableId(targetTableId);
columnDefinition.setTargetTableColumnId(targetTableColumnId);
columnDefinition
.setSourceTableDimensionColumnId(sourceTableDimensionColumnId);
DataType dataType = serviceColumn.getDataType();
columnDefinition.setVisible(visible);
columnDefinition.setEditable(editable);
columnDefinition.setValueType(DataTypeMap.getValueType(dataType));
columnDefinition.setType(getType());
columnDefinition.setPosition(ordinalPosition);
columnDefinition.setTooltipMessage(getTooltipMessage());
columnDefinition.setColumnTypeName(serviceColumn.getColumnType()
.getName());
columnDefinition.setColumnDataType(serviceColumn.getDataType()
.getName());
columnDefinition.setWidth(100);
return columnDefinition;
}
}

View File

@ -0,0 +1,85 @@
package org.gcube.portlets.user.tdwx.datasource.td.map;
import org.gcube.data.analysis.tabulardata.model.column.ColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.CodeColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.DimensionColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.MeasureColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.TimeDimensionColumnType;
import org.gcube.data.analysis.tabulardata.model.column.type.ValidationColumnType;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ColumnTypeMap {
/*
* public static org.gcube.portlets.user.tdwx.shared.model.ColumnType
* map(ColumnType columnType){ if(columnType==null){ return null; }
*
* if(columnType instanceof AnnotationColumnType){
*
* }
*
* if(columnType instanceof AttributeColumnType){
*
* } }
*/
public static boolean isIdColumnType(ColumnType columnType) {
if (columnType instanceof IdColumnType) {
return true;
} else {
return false;
}
}
public static boolean isMeasureColumnType(ColumnType columnType) {
if (columnType instanceof MeasureColumnType) {
return true;
} else {
return false;
}
}
public static boolean isCodeColumnType(ColumnType columnType) {
if (columnType instanceof CodeColumnType) {
return true;
} else {
return false;
}
}
public static boolean isValidationColumnType(ColumnType columnType) {
if (columnType instanceof ValidationColumnType) {
return true;
} else {
return false;
}
}
public static boolean isDimensionColumnType(ColumnType columnType) {
if (columnType instanceof DimensionColumnType) {
return true;
} else {
return false;
}
}
public static boolean isTimeDimensionColumnType(ColumnType columnType) {
if (columnType instanceof TimeDimensionColumnType) {
return true;
} else {
return false;
}
}
}

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.user.tdwx.datasource.td.map;
import org.gcube.data.analysis.tabulardata.model.datatype.BooleanType;
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
import org.gcube.data.analysis.tabulardata.model.datatype.DateType;
import org.gcube.data.analysis.tabulardata.model.datatype.GeometryType;
import org.gcube.data.analysis.tabulardata.model.datatype.IntegerType;
import org.gcube.data.analysis.tabulardata.model.datatype.NumericType;
//import org.gcube.data.analysis.tabulardata.model.datatype.TextType;
import org.gcube.portlets.user.tdwx.shared.model.ValueType;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class DataTypeMap {
public static ValueType getValueType(DataType dataType){
if( dataType instanceof BooleanType){
return ValueType.BOOLEAN;
}
if( dataType instanceof DateType){
return ValueType.DATE;
}
if( dataType instanceof IntegerType){
return ValueType.INTEGER;
}
if( dataType instanceof GeometryType){
return ValueType.GEOMETRY;
}
if( dataType instanceof NumericType){
return ValueType.DOUBLE;
}
return ValueType.STRING;
};
}

View File

@ -0,0 +1,14 @@
package org.gcube.portlets.user.tdwx.datasource.td.opexecution;
/**
* Constants Parameter Name
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpCostants {
public static final String PARAMETER_CHANGE_COLUMN_POSITION_POSITION = "position";
}

View File

@ -0,0 +1,55 @@
package org.gcube.portlets.user.tdwx.datasource.td.opexecution;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.portlets.user.tdwx.datasource.td.exception.OperationException;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for change single column on grid.
* This operation is not supported on TDM beacause ordering of columns on view table
* is not allowed.
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4ChangeSingleColumnPosition extends OpExecutionBuilder {
private static Logger logger = LoggerFactory
.getLogger(OpExecution4ChangeSingleColumnPosition.class);
//private TabularDataService service;
private ColumnsReorderingConfig columnsReorderingConfig;
public OpExecution4ChangeSingleColumnPosition(TabularDataService service,
ColumnsReorderingConfig columnsReorderingConfig) {
//this.service = service;
this.columnsReorderingConfig = columnsReorderingConfig;
}
@Override
public void buildOpEx() throws OperationException {
logger.debug("ColumnsReorderingConfig :" + columnsReorderingConfig);
OperationExecution invocation = null;
/*
OperationDefinition operationDefinition;
operationDefinition = OperationDefinitionMap.map(
OperationsId.ChangeSingleColumnPosition.toString(), service);
Map<String, Object> map = new HashMap<String, Object>();
map.put(OpCostants.PARAMETER_CHANGE_COLUMN_POSITION_POSITION, new Integer(columnsReorderingConfig.getColumnIndex()));
invocation = new OperationExecution(columnsReorderingConfig.getColumnDefinition().getColumnLocalId(),operationDefinition.getOperationId(), map);
*/
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -0,0 +1,26 @@
package org.gcube.portlets.user.tdwx.datasource.td.opexecution;
import org.gcube.portlets.user.tdwx.datasource.td.exception.OperationException;
/**
* Abstract class for build Operation Execution
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
abstract class OpExecutionBuilder {
protected OpExecutionSpec operationExecutionSpec;
public OpExecutionSpec getOperationExecutionSpec(){
return operationExecutionSpec;
}
public void createSpec(){
operationExecutionSpec=new OpExecutionSpec();
}
public abstract void buildOpEx() throws OperationException;
}

View File

@ -0,0 +1,39 @@
package org.gcube.portlets.user.tdwx.datasource.td.opexecution;
import java.util.ArrayList;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
import org.gcube.portlets.user.tdwx.datasource.td.exception.OperationException;
/**
* Operation Execution Director
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecutionDirector {
OpExecutionBuilder operationExecutionBuilder;
public void setOperationExecutionBuilder(
OpExecutionBuilder operationExecutionBuilder) {
this.operationExecutionBuilder = operationExecutionBuilder;
}
public OperationExecution getOperationExecution() {
return operationExecutionBuilder.getOperationExecutionSpec().getOp();
}
public ArrayList<OperationExecution> getListOperationExecution() {
return operationExecutionBuilder.getOperationExecutionSpec().getOps();
}
public void constructOperationExecution() throws OperationException {
operationExecutionBuilder.createSpec();
operationExecutionBuilder.buildOpEx();
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.portlets.user.tdwx.datasource.td.opexecution;
import java.util.ArrayList;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
/**
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecutionSpec {
private OperationExecution op;
private ArrayList<OperationExecution> ops;
public OperationExecution getOp() {
return op;
}
public void setOp(OperationExecution op) {
this.op = op;
}
public ArrayList<OperationExecution> getOps() {
return ops;
}
public void setOps(ArrayList<OperationExecution> ops) {
this.ops = ops;
}
}

View File

@ -0,0 +1,47 @@
package org.gcube.portlets.user.tdwx.datasource.td.trservice;
import org.gcube.data.analysis.tabulardata.commons.webservice.exception.NoSuchOperationException;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.portlets.user.tdwx.datasource.td.exception.OperationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OperationDefinitionMap {
protected static Logger logger = LoggerFactory
.getLogger(OperationDefinitionMap.class);
public static OperationDefinition map(String op, TabularDataService service)
throws OperationException {
OperationDefinition operationDefinition = null;
logger.debug("Retrieve Capability from Service");
try {
operationDefinition = service.getCapability(Long.valueOf(op));
} catch (NumberFormatException e) {
logger.error("No valid operation type: " + op);
e.printStackTrace();
throw new OperationException(
"No valid operation type: " + op);
} catch (NoSuchOperationException e) {
logger.error("NoSuchOperationException: " + e.getLocalizedMessage());
e.printStackTrace();
throw new OperationException(
"NoSuchOperationException: " + e.getLocalizedMessage());
} catch(Throwable e) {
logger.error("Error Retrieving Service Capability: " + e.getLocalizedMessage());
e.printStackTrace();
throw new OperationException(
"Error Retrieving Service Capability: " + e.getLocalizedMessage());
}
return operationDefinition;
}
}

View File

@ -0,0 +1,91 @@
package org.gcube.portlets.user.tdwx.datasource.td.trservice;
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.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.portlets.user.tdwx.datasource.td.exception.OperationException;
import org.gcube.portlets.user.tdwx.datasource.td.opexecution.OpExecution4ChangeSingleColumnPosition;
import org.gcube.portlets.user.tdwx.datasource.td.opexecution.OpExecutionDirector;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Call operations on service
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TRService {
// private static final String TABULAR_RESOURCE_IS_FINAL =
// "Tabular Resource Is Final";
private static final String TABULAR_RESOURCE_IS_LOCKED = "Tabular Resource Is Locked";
private static final String SECURITY_EXCEPTION_RIGHTS = "Security exception, you don't have the required rights!";
private static final Logger logger = LoggerFactory
.getLogger(TRService.class);
private TabularDataService service;
private TabularResourceId tabularResourceId;
public TRService() {
}
public TabularDataService getService() {
return service;
}
public void setService(TabularDataService service) {
this.service = service;
}
public TabularResourceId getTabularResourceId() {
return tabularResourceId;
}
public void setTabularResourceId(TabularResourceId tabularResourceId) {
this.tabularResourceId = tabularResourceId;
}
public void startChangeSingleColumnPosition(
ColumnsReorderingConfig columnsReorderingConfig)
throws OperationException {
try {
TabularResource tabularResource = service
.getTabularResource(tabularResourceId);
if (tabularResource.isLocked()) {
logger.error(TABULAR_RESOURCE_IS_LOCKED);
throw new OperationException(TABULAR_RESOURCE_IS_LOCKED);
}
OpExecution4ChangeSingleColumnPosition opEx = new OpExecution4ChangeSingleColumnPosition(
service, columnsReorderingConfig);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director.getOperationExecution();
logger.debug("OperationInvocation: \n" + invocation);
service.executeSynchMetadataOperation(invocation, tabularResourceId);
return;
} catch (OperationException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new OperationException(SECURITY_EXCEPTION_RIGHTS);
} catch (Throwable e) {
e.printStackTrace();
throw new OperationException("Error Changing The Column Position: "
+ e.getLocalizedMessage());
}
}
}