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:
parent
d5b5e7088c
commit
4d557db7f4
|
@ -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.CodelistMappingFileUploadSession;
|
||||
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.CodelistMappingSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||
|
|
|
@ -1103,29 +1103,35 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
Table table = service.getLastTable(new TabularResourceId(Long
|
||||
.valueOf(trId.getId())));
|
||||
logger.debug("Table retrieved: "+table);
|
||||
|
||||
Table viewTable = null;
|
||||
|
||||
if (table.contains(DatasetViewTableMetadata.class)) {
|
||||
DatasetViewTableMetadata dwm = table
|
||||
.getMetadata(DatasetViewTableMetadata.class);
|
||||
logger.debug("DatasetViewTableMetadata: "+dwm);
|
||||
try {
|
||||
viewTable = service.getTable(dwm
|
||||
.getTargetDatasetViewTableId());
|
||||
} 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();
|
||||
TRId newTRId;
|
||||
|
||||
if (viewTable == null) {
|
||||
TRId newTRId = new TRId();
|
||||
newTRId.setId(trId.getId());
|
||||
logger.debug("ViewTable is null");
|
||||
newTRId=new TRId(trId.getId());
|
||||
newTRId.setTabularResourceType(trId.getTabularResourceType());
|
||||
newTRId.setTableId(String.valueOf(table.getId().getValue()));
|
||||
newTRId.setTableType(table.getTableType().getName());
|
||||
newTRId.setViewTable(false);
|
||||
logger.debug("NewTRId: "+newTRId);
|
||||
tData.setTrId(newTRId);
|
||||
|
||||
tData.setName(table.getName());
|
||||
|
@ -1180,14 +1186,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
tData.setListColumnData(lColumnData);
|
||||
|
||||
} else {
|
||||
TRId newTRId = new TRId();
|
||||
newTRId.setId(trId.getId());
|
||||
logger.debug("ViewTable is not null");
|
||||
newTRId= new TRId(trId.getId());
|
||||
newTRId.setTabularResourceType(trId.getTabularResourceType());
|
||||
newTRId.setTableId(String.valueOf(viewTable.getId().getValue()));
|
||||
newTRId.setTableType(viewTable.getTableType().getName());
|
||||
newTRId.setReferenceTargetTableId(String.valueOf(table.getId()
|
||||
.getValue()));
|
||||
newTRId.setViewTable(true);
|
||||
logger.debug("NewTRId: "+newTRId);
|
||||
tData.setTrId(newTRId);
|
||||
|
||||
tData.setName(viewTable.getName());
|
||||
|
@ -1268,6 +1275,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||
|
||||
logger.debug("getTable(): "+trId);
|
||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||
aslSession.getUsername(), aslSession.getScope()));
|
||||
TabularDataService service = TabularDataServiceFactory.getService();
|
||||
|
@ -1291,12 +1299,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
TableData tData = new TableData();
|
||||
|
||||
if (viewTable == null) {
|
||||
TRId newTRId = new TRId();
|
||||
newTRId.setId(trId.getId());
|
||||
logger.debug("ViewTable is null");
|
||||
TRId newTRId = new TRId(trId.getId());
|
||||
newTRId.setTabularResourceType(trId.getTabularResourceType());
|
||||
newTRId.setTableId(String.valueOf(table.getId().getValue()));
|
||||
newTRId.setTableType(table.getTableType().getName());
|
||||
newTRId.setViewTable(false);
|
||||
logger.debug("NewTRId: "+newTRId);
|
||||
tData.setTrId(newTRId);
|
||||
|
||||
tData.setName(table.getName());
|
||||
|
@ -1351,15 +1360,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
tData.setListColumnData(lColumnData);
|
||||
|
||||
} else {
|
||||
|
||||
TRId newTRId = new TRId();
|
||||
newTRId.setId(trId.getId());
|
||||
logger.debug("ViewTable is not null");
|
||||
TRId newTRId = new TRId(trId.getId());
|
||||
newTRId.setTabularResourceType(trId.getTabularResourceType());
|
||||
newTRId.setTableId(String.valueOf(viewTable.getId().getValue()));
|
||||
newTRId.setTableType(viewTable.getTableType().getName());
|
||||
newTRId.setReferenceTargetTableId(String.valueOf(table.getId()
|
||||
.getValue()));
|
||||
newTRId.setViewTable(true);
|
||||
logger.debug("NewTRId: "+newTRId);
|
||||
tData.setTrId(newTRId);
|
||||
|
||||
tData.setName(viewTable.getName());
|
||||
|
|
|
@ -51,7 +51,7 @@ public class OpExecution4ReplaceColumn extends OpExecutionBuilder {
|
|||
OperationsId.ReplaceColumnByExpression.toString(), service);
|
||||
|
||||
Expression condition = ExpressionGenerator
|
||||
.genReplaceValueParameterCondition(replaceColumnSession);
|
||||
.genReplaceValueParameterCondition(replaceColumnSession,service);
|
||||
Expression value = ExpressionGenerator
|
||||
.genReplaceValueParameterValue(replaceColumnSession);
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class OpExecution4ReplaceColumn extends OpExecutionBuilder {
|
|||
OperationsId.ReplaceColumnByExpression.toString(), service);
|
||||
|
||||
Expression condition = ExpressionGenerator
|
||||
.genReplaceValueParameterCondition(replaceColumnSession);
|
||||
.genReplaceValueParameterCondition(replaceColumnSession,service);
|
||||
Expression value = ExpressionGenerator
|
||||
.genReplaceValueParameterValue(replaceColumnSession);
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ public class ExpressionGenerator {
|
|||
.getLogger(ExpressionGenerator.class);
|
||||
|
||||
public static Expression genReplaceValueParameterCondition(
|
||||
ReplaceColumnSession replaceColumnSession)
|
||||
throws TDGWTServiceException {
|
||||
ReplaceColumnSession replaceColumnSession,
|
||||
TabularDataService service) throws TDGWTServiceException {
|
||||
try {
|
||||
if (replaceColumnSession.isReplaceDimension()) {
|
||||
// Dimension
|
||||
|
@ -58,8 +58,12 @@ public class ExpressionGenerator {
|
|||
.getColumnViewData()
|
||||
.getSourceTableDimensionColumnId()));
|
||||
|
||||
String rowId=QueryService.retrieveColumnDimensionValue(
|
||||
replaceColumnSession.getRowId(), replaceColumnSession.getColumnData(),
|
||||
service);
|
||||
|
||||
Equals eq = new Equals(cr, new TDInteger(
|
||||
Integer.parseInt(replaceColumnSession.getRowId())));
|
||||
Integer.parseInt(rowId)));
|
||||
|
||||
return eq;
|
||||
} else {
|
||||
|
|
|
@ -5,9 +5,12 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
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.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.datatype.value.TDInteger;
|
||||
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;
|
||||
|
@ -106,10 +109,11 @@ public class QueryService {
|
|||
logger.debug("Occurences querySelect:"
|
||||
+ querySelect.toString());
|
||||
} else {
|
||||
ColumnLocalId idColumn=retrieveColumnLocalIdOFIdColumnType(column.getTrId(),
|
||||
service);
|
||||
querySelect = new QuerySelect(
|
||||
Arrays.asList(new QueryColumn(columnId),new QueryColumn(idColumn)));
|
||||
ColumnLocalId idColumn = retrieveColumnLocalIdOFIdColumnType(
|
||||
column.getTrId(), service);
|
||||
querySelect = new QuerySelect(Arrays.asList(
|
||||
new QueryColumn(columnId), new QueryColumn(
|
||||
idColumn)));
|
||||
logger.debug("Occurences querySelect:"
|
||||
+ querySelect.toString());
|
||||
}
|
||||
|
@ -349,7 +353,8 @@ public class QueryService {
|
|||
currentRow.getString(1), 1);
|
||||
} else {
|
||||
occurence = new Occurrences(
|
||||
currentRow.getString(0),currentRow.getString(1), 1);
|
||||
currentRow.getString(0),
|
||||
currentRow.getString(1), 1);
|
||||
}
|
||||
break;
|
||||
case CastValidation:
|
||||
|
@ -447,7 +452,6 @@ public class QueryService {
|
|||
}
|
||||
return columnLocalId;
|
||||
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
logger.error("QueryService - retrieveColumnLocalIdOFIdColumn: "
|
||||
+ e.getLocalizedMessage());
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,36 @@ public class TableData implements Serializable {
|
|||
protected String name;
|
||||
protected String typeName;
|
||||
protected String typeCode;
|
||||
protected String metaData;
|
||||
protected String metaData; //Metadata Description
|
||||
|
||||
protected ArrayList<ColumnData> listColumnData;
|
||||
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() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class ReplaceColumnSession implements Serializable {
|
|||
|
||||
}
|
||||
|
||||
//Simple Replace
|
||||
public ReplaceColumnSession(String value, String replaceValue, TRId trId,
|
||||
ColumnData columnData, String rowId) {
|
||||
this.value = value;
|
||||
|
@ -36,6 +37,8 @@ public class ReplaceColumnSession implements Serializable {
|
|||
this.replaceDimension = false;
|
||||
}
|
||||
|
||||
|
||||
//Dimension Replace
|
||||
public ReplaceColumnSession(String value, String replaceValue, TRId trId,
|
||||
ColumnData columnData, String rowId, boolean replaceDimension) {
|
||||
this.value = value;
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.junit.Test;
|
|||
*
|
||||
*/
|
||||
public class TestServiceTable {
|
||||
private final static long trId = 238;
|
||||
private final static long searchTableId=4312;
|
||||
private final static long trId = 264;
|
||||
private final static long searchTableId=4722;
|
||||
private String user=Constants.DEFAULT_USER;
|
||||
private String scope=Constants.DEFAULT_SCOPE;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class TestServiceTable {
|
|||
return;
|
||||
}
|
||||
|
||||
System.out.println(lastTable.toString());
|
||||
System.out.println("LastTable[TR id:"+trId+"] :"+lastTable.toString());
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class TestServiceTable {
|
|||
return;
|
||||
}
|
||||
|
||||
System.out.println(searchTable.toString());
|
||||
System.out.println("SearchTable["+searchTableId+"]: "+searchTable.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue