Fixed Replace Value on TD with view column

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98564 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-07-11 14:25:31 +00:00
parent d5b5e7088c
commit 4d557db7f4
8 changed files with 174 additions and 41 deletions

View File

@ -17,7 +17,6 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; 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.CodelistMappingFileUploadSession;
import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager; import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;

View File

@ -1103,29 +1103,35 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Table table = service.getLastTable(new TabularResourceId(Long Table table = service.getLastTable(new TabularResourceId(Long
.valueOf(trId.getId()))); .valueOf(trId.getId())));
logger.debug("Table retrieved: "+table);
Table viewTable = null; Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) { if (table.contains(DatasetViewTableMetadata.class)) {
DatasetViewTableMetadata dwm = table DatasetViewTableMetadata dwm = table
.getMetadata(DatasetViewTableMetadata.class); .getMetadata(DatasetViewTableMetadata.class);
logger.debug("DatasetViewTableMetadata: "+dwm);
try { try {
viewTable = service.getTable(dwm viewTable = service.getTable(dwm
.getTargetDatasetViewTableId()); .getTargetDatasetViewTableId());
} catch (Exception e) { } catch (Exception e) {
logger.error("view table not found"); logger.error("View table not found: "+e.getLocalizedMessage());
} }
} else {
logger.debug("Table not contains DataseViewTableMetadata");
} }
TableData tData = new TableData(); TableData tData = new TableData();
TRId newTRId;
if (viewTable == null) { if (viewTable == null) {
TRId newTRId = new TRId(); logger.debug("ViewTable is null");
newTRId.setId(trId.getId()); newTRId=new TRId(trId.getId());
newTRId.setTabularResourceType(trId.getTabularResourceType()); newTRId.setTabularResourceType(trId.getTabularResourceType());
newTRId.setTableId(String.valueOf(table.getId().getValue())); newTRId.setTableId(String.valueOf(table.getId().getValue()));
newTRId.setTableType(table.getTableType().getName()); newTRId.setTableType(table.getTableType().getName());
newTRId.setViewTable(false); newTRId.setViewTable(false);
logger.debug("NewTRId: "+newTRId);
tData.setTrId(newTRId); tData.setTrId(newTRId);
tData.setName(table.getName()); tData.setName(table.getName());
@ -1180,16 +1186,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
tData.setListColumnData(lColumnData); tData.setListColumnData(lColumnData);
} else { } else {
TRId newTRId = new TRId(); logger.debug("ViewTable is not null");
newTRId.setId(trId.getId()); newTRId= new TRId(trId.getId());
newTRId.setTabularResourceType(trId.getTabularResourceType()); newTRId.setTabularResourceType(trId.getTabularResourceType());
newTRId.setTableId(String.valueOf(viewTable.getId().getValue())); newTRId.setTableId(String.valueOf(viewTable.getId().getValue()));
newTRId.setTableType(viewTable.getTableType().getName()); newTRId.setTableType(viewTable.getTableType().getName());
newTRId.setReferenceTargetTableId(String.valueOf(table.getId() newTRId.setReferenceTargetTableId(String.valueOf(table.getId()
.getValue())); .getValue()));
newTRId.setViewTable(true); newTRId.setViewTable(true);
logger.debug("NewTRId: "+newTRId);
tData.setTrId(newTRId); tData.setTrId(newTRId);
tData.setName(viewTable.getName()); tData.setName(viewTable.getName());
tData.setTypeName(viewTable.getTableType().getName()); tData.setTypeName(viewTable.getTableType().getName());
tData.setTypeCode(viewTable.getTableType().getCode()); tData.setTypeCode(viewTable.getTableType().getCode());
@ -1241,7 +1248,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
tData.setListColumnData(lColumnData); tData.setListColumnData(lColumnData);
} }
logger.debug("getLastTable: " + tData); logger.debug("getLastTable: " + tData);
return tData; return tData;
@ -1267,7 +1274,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("getTable(): "+trId);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope())); aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
@ -1291,12 +1299,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TableData tData = new TableData(); TableData tData = new TableData();
if (viewTable == null) { if (viewTable == null) {
TRId newTRId = new TRId(); logger.debug("ViewTable is null");
newTRId.setId(trId.getId()); TRId newTRId = new TRId(trId.getId());
newTRId.setTabularResourceType(trId.getTabularResourceType()); newTRId.setTabularResourceType(trId.getTabularResourceType());
newTRId.setTableId(String.valueOf(table.getId().getValue())); newTRId.setTableId(String.valueOf(table.getId().getValue()));
newTRId.setTableType(table.getTableType().getName()); newTRId.setTableType(table.getTableType().getName());
newTRId.setViewTable(false); newTRId.setViewTable(false);
logger.debug("NewTRId: "+newTRId);
tData.setTrId(newTRId); tData.setTrId(newTRId);
tData.setName(table.getName()); tData.setName(table.getName());
@ -1351,15 +1360,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
tData.setListColumnData(lColumnData); tData.setListColumnData(lColumnData);
} else { } else {
logger.debug("ViewTable is not null");
TRId newTRId = new TRId(); TRId newTRId = new TRId(trId.getId());
newTRId.setId(trId.getId());
newTRId.setTabularResourceType(trId.getTabularResourceType()); newTRId.setTabularResourceType(trId.getTabularResourceType());
newTRId.setTableId(String.valueOf(viewTable.getId().getValue())); newTRId.setTableId(String.valueOf(viewTable.getId().getValue()));
newTRId.setTableType(viewTable.getTableType().getName()); newTRId.setTableType(viewTable.getTableType().getName());
newTRId.setReferenceTargetTableId(String.valueOf(table.getId() newTRId.setReferenceTargetTableId(String.valueOf(table.getId()
.getValue())); .getValue()));
newTRId.setViewTable(true); newTRId.setViewTable(true);
logger.debug("NewTRId: "+newTRId);
tData.setTrId(newTRId); tData.setTrId(newTRId);
tData.setName(viewTable.getName()); tData.setName(viewTable.getName());

View File

@ -51,7 +51,7 @@ public class OpExecution4ReplaceColumn extends OpExecutionBuilder {
OperationsId.ReplaceColumnByExpression.toString(), service); OperationsId.ReplaceColumnByExpression.toString(), service);
Expression condition = ExpressionGenerator Expression condition = ExpressionGenerator
.genReplaceValueParameterCondition(replaceColumnSession); .genReplaceValueParameterCondition(replaceColumnSession,service);
Expression value = ExpressionGenerator Expression value = ExpressionGenerator
.genReplaceValueParameterValue(replaceColumnSession); .genReplaceValueParameterValue(replaceColumnSession);
@ -72,7 +72,7 @@ public class OpExecution4ReplaceColumn extends OpExecutionBuilder {
OperationsId.ReplaceColumnByExpression.toString(), service); OperationsId.ReplaceColumnByExpression.toString(), service);
Expression condition = ExpressionGenerator Expression condition = ExpressionGenerator
.genReplaceValueParameterCondition(replaceColumnSession); .genReplaceValueParameterCondition(replaceColumnSession,service);
Expression value = ExpressionGenerator Expression value = ExpressionGenerator
.genReplaceValueParameterValue(replaceColumnSession); .genReplaceValueParameterValue(replaceColumnSession);

View File

@ -38,8 +38,8 @@ public class ExpressionGenerator {
.getLogger(ExpressionGenerator.class); .getLogger(ExpressionGenerator.class);
public static Expression genReplaceValueParameterCondition( public static Expression genReplaceValueParameterCondition(
ReplaceColumnSession replaceColumnSession) ReplaceColumnSession replaceColumnSession,
throws TDGWTServiceException { TabularDataService service) throws TDGWTServiceException {
try { try {
if (replaceColumnSession.isReplaceDimension()) { if (replaceColumnSession.isReplaceDimension()) {
// Dimension // Dimension
@ -58,8 +58,12 @@ public class ExpressionGenerator {
.getColumnViewData() .getColumnViewData()
.getSourceTableDimensionColumnId())); .getSourceTableDimensionColumnId()));
String rowId=QueryService.retrieveColumnDimensionValue(
replaceColumnSession.getRowId(), replaceColumnSession.getColumnData(),
service);
Equals eq = new Equals(cr, new TDInteger( Equals eq = new Equals(cr, new TDInteger(
Integer.parseInt(replaceColumnSession.getRowId()))); Integer.parseInt(rowId)));
return eq; return eq;
} else { } else {
@ -221,13 +225,13 @@ public class ExpressionGenerator {
.getValidationColumnColumnId(); .getValidationColumnColumnId();
ColumnData column = occurrencesSession.getColumnData(); ColumnData column = occurrencesSession.getColumnData();
String tdId; String tdId;
if(column.getTrId().isViewTable()){ if (column.getTrId().isViewTable()) {
tdId=column.getTrId().getReferenceTargetTableId(); tdId = column.getTrId().getReferenceTargetTableId();
} else { } else {
tdId=column.getTrId().getTableId(); tdId = column.getTrId().getTableId();
} }
TableId tableId = new TableId(Long.valueOf(tdId)); TableId tableId = new TableId(Long.valueOf(tdId));
if (validationColumnColumnId == null if (validationColumnColumnId == null
|| validationColumnColumnId.isEmpty()) { || validationColumnColumnId.isEmpty()) {
ArrayList<String> validationColumnReferences = column ArrayList<String> validationColumnReferences = column

View File

@ -5,9 +5,12 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.Equals;
import org.gcube.data.analysis.tabulardata.model.column.Column; 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.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.column.ColumnReference;
import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType; import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType;
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDInteger;
import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryFilter; import org.gcube.data.analysis.tabulardata.query.parameters.QueryFilter;
@ -106,10 +109,11 @@ public class QueryService {
logger.debug("Occurences querySelect:" logger.debug("Occurences querySelect:"
+ querySelect.toString()); + querySelect.toString());
} else { } else {
ColumnLocalId idColumn=retrieveColumnLocalIdOFIdColumnType(column.getTrId(), ColumnLocalId idColumn = retrieveColumnLocalIdOFIdColumnType(
service); column.getTrId(), service);
querySelect = new QuerySelect( querySelect = new QuerySelect(Arrays.asList(
Arrays.asList(new QueryColumn(columnId),new QueryColumn(idColumn))); new QueryColumn(columnId), new QueryColumn(
idColumn)));
logger.debug("Occurences querySelect:" logger.debug("Occurences querySelect:"
+ querySelect.toString()); + querySelect.toString());
} }
@ -349,7 +353,8 @@ public class QueryService {
currentRow.getString(1), 1); currentRow.getString(1), 1);
} else { } else {
occurence = new Occurrences( occurence = new Occurrences(
currentRow.getString(0),currentRow.getString(1), 1); currentRow.getString(0),
currentRow.getString(1), 1);
} }
break; break;
case CastValidation: case CastValidation:
@ -420,7 +425,7 @@ public class QueryService {
} }
} }
/** /**
* Retrieve ColumnLocalId value of IdColumnType * Retrieve ColumnLocalId value of IdColumnType
* *
@ -441,13 +446,12 @@ public class QueryService {
List<Column> cols = table.getColumns(); List<Column> cols = table.getColumns();
for (Column c : cols) { for (Column c : cols) {
if (c.getColumnType() instanceof IdColumnType) { if (c.getColumnType() instanceof IdColumnType) {
columnLocalId=c.getLocalId(); columnLocalId = c.getLocalId();
break; break;
} }
} }
return columnLocalId; return columnLocalId;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.error("QueryService - retrieveColumnLocalIdOFIdColumn: " logger.error("QueryService - retrieveColumnLocalIdOFIdColumn: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -458,7 +462,7 @@ public class QueryService {
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage()); throw new TDGWTServiceException(e.getLocalizedMessage());
} catch (Throwable e){ } catch (Throwable e) {
logger.error("QueryService - retrieveColumnLocalIdOFIdColumn: " logger.error("QueryService - retrieveColumnLocalIdOFIdColumn: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
@ -467,4 +471,93 @@ public class QueryService {
} }
public static String retrieveColumnDimensionValue(String rowId,
ColumnData column, TabularDataService service)
throws TDGWTServiceException {
try {
logger.debug("RetriveColumnDimensionValue: [rowId=" + rowId
+ ", column=" + column + "]");
column.getColumnViewData().getSourceTableDimensionColumnId();
TableId tableId = new TableId(new Long(column.getTrId()
.getTableId()));
ColumnLocalId columnId = new ColumnLocalId(column.getColumnId());
QuerySelect querySelect = null;
if (!column.isViewColumn()) {
logger.error("The column selected is not a view column:"
+ column);
throw new TDGWTServiceException(
"The column selected is not a view column");
}
ColumnLocalId sourceColumnId = new ColumnLocalId(column
.getColumnViewData().getSourceTableDimensionColumnId());
querySelect = new QuerySelect(Arrays.asList(new QueryColumn(
columnId), new QueryColumn(sourceColumnId)));
logger.debug("QuerySelect:" + querySelect.toString());
QueryPage queryPage = null;// All occurences
logger.debug("Occurences queryPage all");
ColumnLocalId idColumn = retrieveColumnLocalIdOFIdColumnType(
column.getTrId(), service);
ColumnReference cr = new ColumnReference(tableId, idColumn);
Equals rowIdEqual = new Equals(cr, new TDInteger(
Integer.parseInt(rowId)));
QueryFilter queryFilter = new QueryFilter(rowIdEqual);
logger.debug("Query on " + tableId.toString() + " queryPage:"
+ queryPage + ", queryFilter:" + queryFilter
+ ", querySelect:" + querySelect);
String serviceJson = null;
logger.debug("3-QueryAsJson-->[tableId:" + tableId + ", queryPage:"
+ queryPage + ", queryFilter:" + queryFilter
+ ", querySelect:" + querySelect + "]");
serviceJson = service.queryAsJson(tableId, queryPage, queryFilter,
querySelect);
logger.debug("Created serviceJson");
// logger.debug(serviceJson);
JSONArray currentRow = null;
int i = 0;
int totalRows = -1;
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");
String colValue = null;
String dimensionValue = null;
if(i < totalRows) {
currentRow = rows.getJSONArray(i);
colValue = currentRow.getString(0);
dimensionValue = currentRow.getString(1);
}
if (dimensionValue == null) {
logger.error("The column selected has not a dimension with valid value: "
+ column + ", dimenensionValue: " + dimensionValue);
throw new TDGWTServiceException(
"The column selected has not a dimension with valid value");
} else {
logger.debug("Retrieved: [ColumnValue:" + colValue
+ ", DimensionValue:" + dimensionValue + "]");
}
return dimensionValue;
} catch (Throwable e) {
logger.error("QueryService: " + e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
} }

View File

@ -19,11 +19,36 @@ public class TableData implements Serializable {
protected String name; protected String name;
protected String typeName; protected String typeName;
protected String typeCode; protected String typeCode;
protected String metaData; protected String metaData; //Metadata Description
protected ArrayList<ColumnData> listColumnData; protected ArrayList<ColumnData> listColumnData;
protected TRId trId; protected TRId trId;
public TableData() {
}
/**
*
* @param id Only for insert in grid
* @param name Name
* @param typeName For example: Dataset View
* @param typeCode For example: DATASETVIEW
* @param metaData A description
* @param listColumnData
* @param trId
*/
public TableData(String id, String name, String typeName, String typeCode,
String metaData, ArrayList<ColumnData> listColumnData, TRId trId) {
this.id=id;
this.name=name;
this.typeName=typeName;
this.typeCode=typeCode;
this.metaData=metaData;
this.listColumnData=listColumnData;
this.trId=trId;
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -26,6 +26,7 @@ public class ReplaceColumnSession implements Serializable {
} }
//Simple Replace
public ReplaceColumnSession(String value, String replaceValue, TRId trId, public ReplaceColumnSession(String value, String replaceValue, TRId trId,
ColumnData columnData, String rowId) { ColumnData columnData, String rowId) {
this.value = value; this.value = value;
@ -35,7 +36,9 @@ public class ReplaceColumnSession implements Serializable {
this.rowId = rowId; this.rowId = rowId;
this.replaceDimension = false; this.replaceDimension = false;
} }
//Dimension Replace
public ReplaceColumnSession(String value, String replaceValue, TRId trId, public ReplaceColumnSession(String value, String replaceValue, TRId trId,
ColumnData columnData, String rowId, boolean replaceDimension) { ColumnData columnData, String rowId, boolean replaceDimension) {
this.value = value; this.value = value;

View File

@ -21,8 +21,8 @@ import org.junit.Test;
* *
*/ */
public class TestServiceTable { public class TestServiceTable {
private final static long trId = 238; private final static long trId = 264;
private final static long searchTableId=4312; private final static long searchTableId=4722;
private String user=Constants.DEFAULT_USER; private String user=Constants.DEFAULT_USER;
private String scope=Constants.DEFAULT_SCOPE; private String scope=Constants.DEFAULT_SCOPE;
@ -54,7 +54,7 @@ public class TestServiceTable {
return; return;
} }
System.out.println(lastTable.toString()); System.out.println("LastTable[TR id:"+trId+"] :"+lastTable.toString());
} }
@ -77,7 +77,7 @@ public class TestServiceTable {
return; return;
} }
System.out.println(searchTable.toString()); System.out.println("SearchTable["+searchTableId+"]: "+searchTable.toString());
} }
} }